Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs port error with Heroku

Tags:

node.js

heroku

I am trying to push my app to heroku bu I am getting this problem where I am using the correct port number using the process.env.PORT variable but still I am getting this error message:

heroku[web.1]:  Starting process with command `node app.js`
app[web.1]:     info  - socket.io started
app[web.1]: Express server listening on port 49559 in development mode
heroku[web.1]:  Error R11 (Bad bind) -> Process bound to port 10843, should be 49559 (see environment variable PORT)
heroku[web.1]:  Stopping process with SIGKILL
heroku[web.1]:  Process exited

You can see in this error message that app is using the right port but still heroku shows the bad bind error. Any help is appreciated.

like image 822
Muthuswamy Avatar asked Dec 12 '22 08:12

Muthuswamy


1 Answers

Heroku will pass the port in a environment variable named PORT, which means you can access it via process.env.

Simply change your code to call listen with the proper port

var port = process.env.PORT || 3000;
app.listen(port);
like image 193
Jakub Arnold Avatar answered Dec 14 '22 22:12

Jakub Arnold