2

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?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
VicDev
  • 21
  • 3
  • Does this answer your question? [First Heroku deploy failed \`error code=H10\`](https://stackoverflow.com/questions/14322989/first-heroku-deploy-failed-error-code-h10) – Youssouf Oumar Aug 15 '22 at 18:19
  • 1
    Remove all references to any files that are not index.js. Then push it and see if you still get AppCrashed. If it still crashes, the problem is in index.js, if it works then add back the routes one by one until it errors and you'll know what file is broken. You can also put the whole thing in a try/catch with a console.warn(e) in the catch to see what the actual cause of the crash is. – Sam Spade Aug 15 '22 at 18:29

0 Answers0