142

I deployed my app to Heroku. It's a node.js + express + socket.io app and this is the package.json file

{
  "name": "game_test",
  "author": "Ilya",
  "description": "A test app for our board game",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "dependencies": {
    "express": "3.0.6",
    "jade": "*",
    "socket.io" : "*"
  },
 "engines": {
      "node": "0.8.14"
  }
}

This is the log I get:

heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=

What does it mean?

ilyo
  • 35,851
  • 46
  • 106
  • 159
  • 8
    "App crashed" has the obvious meaning: your app crashed. Look further up in your logs to see why, or `heroku restart` to launch it again so you can watch it crash again. – willglynn Jan 14 '13 at 17:04

34 Answers34

271

Found solution for me here: Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)

In my case, my app crashed because it was hard setting the PORT, instead of using the port that heroku dynamically sets, which can be accessed with process.env.PORT

app.listen(process.env.PORT || 3000, function(){
  console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});
Martin Schaer
  • 3,986
  • 1
  • 23
  • 28
  • 4
    These days most of us are using ES6. So same answer can also be written in ES6 using arrow function. app.listen(process.env.PORT || 3000, () => { console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env); }); – Hemadri Dasari Sep 06 '18 at 06:07
  • This happened to me, which was caused by trying to import a library that was not in my package.json file. – Yvan Pearson Apr 04 '19 at 22:10
  • Where should the above mentioned line of code be added? – Praveen Kumar-M Nov 08 '20 at 19:32
  • 1
    @PraveenKumar-M usually that line goes in the main file of your server (index.js). `app` is an instance of express – Martin Schaer Nov 11 '20 at 23:46
  • I get `TypeError: this.address is not a function` in `Node V17`. – Timo Feb 06 '22 at 15:05
  • The improved `string-ish` way is `app.listen(process.env.port || 3000, () => {// port = this.address().port; console.log(`listening in ${app.settings.env} mode`);});` – Timo Feb 06 '22 at 15:09
67

I just had a similar issue with my app, I got the issue after a migration of the DB, after trying many options, the one that helped me was this:

heroku restart

(Using Heroku toolbelt for mac)

clarenswd
  • 933
  • 9
  • 17
  • 2
    I was getting the same error code and mine used to work but this all of a sudden started happening. The "heroku restart" command cleared this up for me. – Mike Feb 20 '16 at 02:51
  • 1
    Same thing happened to me after adding New Relic. Restart fixed my issue – khollenbeck Nov 30 '18 at 13:51
  • My app was working on localhost and if that's the case `heroku restart` is the correct thing to do first. Thanks! – Ian Poston Framer May 13 '22 at 04:08
21

I had this issue, the only problem was my Procfile was like this

web : node index.js

and I changed to

web:node index.js

the only problem was spaces

Sayandeep Majumdar
  • 370
  • 1
  • 9
  • 20
Arian Nargesi
  • 506
  • 1
  • 4
  • 13
7

In my case, i found same error because there is version difference of node and npm on my local machine and defined in package.json version.

"engines": {
  "node": "0.8",
  "npm": "1.2.x"
}

when i check using

node --version : v0.10.41
npm --version : 1.4.29

when i update my package.json to

 "engines": {
  "node": "0.10.41",
  "npm": "1.4.29"
}

It works fine :)

Mahesh Singh Chouhan
  • 2,558
  • 1
  • 16
  • 26
7

In my case there was no start command in the script section of package.json file. When I created the package.json file with npm init I did not create a start script command. So I went to the package.json file, under scripts I added a new entry:

 "scripts": {
    "start": "node index.js"
  },

Saved it and uploaded to Heroku and it worked

Valentin
  • 2,772
  • 1
  • 27
  • 40
Mahmoud Awad
  • 103
  • 1
  • 5
6

in my case adding process.env.PORT || 3000 to my http server script, resolved. My heroku log reported 'H20' error and 503 http status.

Ewertom Moraes
  • 121
  • 1
  • 4
4

In my case, my Procfile was pointing to the wrong file (bot.js which I previously used) so once I updated it, the error was gone.

3

Also check your database connection. I forgot to change my database connection from localhost and this crashed my app once it was pushed to heroku.

lindsaymacvean
  • 4,419
  • 2
  • 19
  • 21
3

I faced this same problem and none of the answers above helped me. What i did was run:

node --version

and in the package.json add the engines section with your node version:

{
  "name": "myapp",
  "description": "a really cool app",
  "version": "1.0.0",
  "engines": {
    "node": "6.11.1"
  }
}
Martin De Simone
  • 2,108
  • 3
  • 16
  • 30
3

upon using hapi18, I find taking out the "host" field and setting the port to:

port: process.env.PORT || 5000 did the trick.

3

Old Thread, but I fix this issue by setting PORT constant to process.env.PORT ||

For some weird reason, it wanted to search Env first.

Isaac Frank
  • 351
  • 3
  • 12
2

I had a typo

const PORT = process.env.PORT||'8080';

used to be

const PORT = process.env.port||'8080';

Omar
  • 2,726
  • 2
  • 32
  • 65
2

If you locally start node server by nodemon, like I did, and it locally works, try npm start. Nodemon was telling me no errors, but npm start told me a lot of them in a understandable way and then I could solve them by following another posts here. I hope it helps to someone.

Erik
  • 303
  • 1
  • 3
  • 12
1

In my own case, i got this error because i refuse to add a Procfile to my node js app and my "main": "app.js" was initially pointing to another js file as main. so doing these chnages get it fixed for me

forestbaba
  • 189
  • 1
  • 4
1

Password contained a % broke it for me.

Nash Worth
  • 2,524
  • 1
  • 21
  • 28
1

In my case, I forgot to set database env for deployment. you can set env by this command (I'm using mLab for MongoDB server)

heroku config:set MONGO_URI='mongodb://address'

minjun youn
  • 21
  • 1
  • 7
1

For me it was Package.json it was empty from dependencies even though i thought i did install them.. so I had to reinstall them with --save option in the end and verify they were added to the package.json.. and then push it again and it worked.

Roman
  • 11
  • 1
1

My port was set to config.httpPort which resolves to 80. I fixed it by doing this:

const PORT = process.env.PORT || config.httpPort;

app.listen(PORT, ...)

Thanks a lot, it wasted me a lot of hours last night.

1

In my case I had code=H10 and status=503 because my Procfile:

web: node build/server.js

and I included /build in .gitignore

Donovant
  • 3,091
  • 8
  • 40
  • 68
1

My start command had env-cmd -f ./config/prod.env node index.js.

after changing to: node index.js it got fixed.

Itay Tur
  • 683
  • 1
  • 15
  • 40
1

I got the same issue, the problem was my Profile was like this:

web: gunicorn__init__:app

Notice with the above there was no space between gunicorn and __ init __

instead of web: gunicorn __init__:app

1

in my case the problem solved by changing the order : From : app.listen(2000 || process.env.PORT); to : app.listen(process.env.PORT || 2000);

othmane-be
  • 82
  • 1
  • 7
1

Just got this error and resolved it. For anyone who has tried the other methods and failed, do check your Procfile path. My server was in the backend folder yet I only typed web: node server.js. I resolved the error after changing it to web: node backend/server.js

Josh
  • 25
  • 7
0

I got the same above error as "app crashed" and H10 error and the heroku app logs is not showing much info related to the error msg reasons. Then I restarted the dynos in heroku and then it showed the error saying additional curly brace in one of the index.js files in my setup. The issue got fixed once it is removed and redeployed the app on heroku.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Praveen
  • 37
  • 7
0

The H10 error code could mean many different things. In my case, the first time was because I didn't know that Heroku isn't compatible with Sqlite3, the second time was because I accidentally pushed an update with Google analytics working in development as well as production.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
0

Older thread, but for me I didn't set my .env vars in the Heroku console.

Josh Lavely
  • 328
  • 1
  • 3
  • 10
0

i was using body-Parser that throw exception

const bodyParser = require('body-Parser')    
//Bodyparser Middleware
app.use(bodyparser.json())

intead of using

    //Bodyparser Middleware
    app.use(express.json())

this resolved my issue

Sadaf Sid
  • 1,510
  • 3
  • 17
  • 30
0

I want to register here what was my solution for this error which was a simple file not updated to Github.

I have a full stack project, and my files are structured both root directory for backend and client for the frontend (I am using React.js). All came down to the fact that I was mistakenly pushing the client folder only to Github and all my changes which had an error (missing a comma in a object's instance in my index.js) was not updated in the backend side. Since this Heroku fetches all updates from Github Repository, I couldn't access my server and the error persisted. Then all I had to do was to commit and push to the root directory and update all the changes of the project and everything came back to work again.

Luis Febro
  • 1,733
  • 1
  • 16
  • 21
0

I struggle with the same error for hours, but I was able to solve it. I installed multer and aws-sdk as a devDependencies by mistake, instead of just dependencies. So, anyone who has the same error, just double-check your package.json file.

Also, a small tip for the property of the engine in package.json.

enter code here
//The greater or equal operators will make sure that you use the right node 
//version 
//even if your current node is greater version than npm node

"engines": {
"node": ">= 0.8.14"
},


//insted of
"engines": {
  "node": "0.8.14"
}
0

I was deploying python Django framework when I got this error because I forget to put my app name web: gunicorn plaindjango.wsgi:application --log-file - instead of plaindjango

Talha Anwar
  • 2,699
  • 4
  • 23
  • 62
0

For me, I had things unnecessarily split into separate folders. I'm running plotly dash and I had my Procfile, and Pipfile (and lock) together, but separate from the other features of my app (run.py and app.py, the actual content of the pages being used was in a subfolder). So joining much of that together repaired my H10 error

Tclack88
  • 101
  • 7
0
// PORT
const PORT = process.env.PORT || 8081;

// Listen on port 8081
app.listen(PORT, () =>
  console.log(`Application is listening on port ${PORT}!`)
);

process.env.PORT will handle whatever port is needed on, for example, Heroku, AWS etc.

Clancinio
  • 734
  • 6
  • 21
  • 40
0

In my case it was due to the heap memory limit.

  1. Just add some of the dependencies to the dev dependencies object.
  2. Remove unused modules.

You can see the exact error using heroku restart and if it is the memory limit, then upgrade your heroku account.

Nagibaba
  • 4,218
  • 1
  • 35
  • 43
0

I was facing the same problem (H10 GET=/). I tried changing PORT but with no results. Turns out the solution was simple. I edited one line in my package.json file. From:

 "scripts": {
 "start": "nodemon app.js"

To:

 "scripts": {
 "start": "node app.js"
Nibelur
  • 27
  • 7