3

I know this has been asked a few times but I haven't been able to find a solution that works yet. I'm trying to have my node server deployed on Heroku and build succeeds but the log prints the following message. I'm also using mongoose and have no problem deploying locally.

2019-02-10T22:30:09.912634+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=chatifydotcom.herokuapp.com request_id=b486e511-ff21-4166-ae1d-07bf5796691e fwd="74.196.2.211" dyno= connect= service= status=503 bytes= protocol=https

2019-02-10T22:30:10.287542+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=chatifydotcom.herokuapp.com request_id=18f17ca0-56df-4dfe-a560-d890a699f17f fwd="74.196.2.211" dyno= connect= service= status=503 bytes= protocol=https

Server.js

 const uri = process.env.MONGODB_URI || "mongodb://localhost:27017/chat"
mongoose
  .connect(uri, { useNewUrlParser: true })
  .then(() => console.log("MongoDB Connected"))
  .catch(err => console.log(err.message))

    const port = process.env.PORT || 9000
server.listen(port, () => {
  console.log(`This server is over ${port}`)
})
LTFoReal
  • 377
  • 5
  • 20

5 Answers5

11

I'm working on this same error right now. The Heroku error code H10 essentially just means the app crashed, as it says, but you need to do more digging to figure out what the actual problem is.

You can do that by starting app on a heroku dyno from the console: EDIT: command for running the console may vary, I did this on Windows

heroku run bash
npm start

Then you can see the console output of your app, and more specific error info for troubleshooting. Then you can fix or ask a more specific question on here.

YoungZaphod
  • 472
  • 1
  • 5
  • 15
  • awesome, I'll give this a shot. So far I've just been using heroku logs -t and trying to fix based on that but it wasn't giving me much to go on. – LTFoReal Feb 12 '19 at 19:04
  • @LTFoReal yeah those won't give you much to go on, definitely run it from the console on heroku and see what that gives you. Post if you have trouble running that. – YoungZaphod Feb 14 '19 at 06:45
  • @LTFoReal if this helped you on investigating code H10 errors, can you accept the answer? Thanks! – YoungZaphod Feb 16 '19 at 07:38
  • hey sorry this was very helpful.. it helped me find the problem Heroku was having which was an issue with the heroku address that I was passing as MONGODB_URI. Thanks again for your help. – LTFoReal Jun 14 '19 at 16:35
2

I've also tried the solutions from the answers to this question

My node version is fine, my port setting is okay. None of them actually worked. My case is just a simple js script with express.

Then I tried to turn this

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon index.js",
    "start": "node index.js"
  }

To this

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon index",
    "start": "node index"
  }

It works.

xzifan
  • 27
  • 5
1

I got faced the same issue and I got rid that finally. In my case I was performing git push heroku main which also main isn't the default branch. I had to go to master branch first(default branch), merge the code with my other branch and then heroku git:remote -a <repoName> and git push heroku master. HOPE this can help!

Ibrahim BHMBS
  • 379
  • 3
  • 6
1

I was running into this issue as well. I found that it came down to a conflict in the node version being used. I am using 16.14.0; Heroku was deploying 17.5.0. As it turns out, 17.5.0 and mongoose are not getting along. I had this in my package.json:

"engines": {
  "node": ">=16.14.0",
  "npm": ">=8.3.1"
}

Making this change resolved the issue:

"engines": {
  "node": "^16.14.0",
  "npm": "^8.3.1"
}
JonW
  • 41
  • 6
0

My problem was with my IP address in my Mongo DB Atlas after deploy. Firstly, in your command line type: $ npm run. Check and fix the errors in your pakage.json. Then, run npm with heroku:$ heroku run npm start. Do not Cancel operation. Meanwhile, match the name and open your app from heroku site. It will either run or show error messages.

My error message: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's.

Log in to MongoDB atlas. Then, go to Network Access on left side. Then select +Add IP Address. Then, allow access from anywhere (0.0.0.0/0). ReRun the heroku app again.