I followed a YouTube tutorial and created a full stack (MERN) social media application. I am having issues deploying it. I have tried every solution I could find related to heroku[router] code=H10
, but none of them solved my issues. Here are my files related.
package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.5.1",
"multer": "^1.4.5-lts.1",
"nodemon": "^2.0.19"
}
}
index.js
import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import dotenv from "dotenv";
import cors from "cors";
import AuthRoute from "./Routes/AuthRoute.js";
import UserRoute from "./Routes/UserRoute.js";
import PostRoute from "./Routes/PostRoute.js";
import UploadRoute from "./Routes/UploadRoute.js";
// Routes
const app = express();
//Public images
app.use(express.static('public'))
app.use('/images', express.static('images'))
// Middleware
app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());
dotenv.config();
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() =>
app.listen(process.env.PORT, () =>
console.log("Connected")
)
)
.catch((error) => console.log(error));
// Usage of routes
app.use("/auth", AuthRoute);
app.use("/user", UserRoute);
app.use("/posts", PostRoute);
app.use('/upload', UploadRoute);
I have also edited the config variables and have
MONGO_URI
linked to my MongoDB.
I originally had my start script as nodemon index.js. I changed it to direct node to start at index.js. Perhaps that is part of the issue. I changed it to just run node instead of nodemon.
What am I doing wrong?