Muthuswamy
Muthuswamy

Reputation: 41

Nodejs port error with 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.

Upvotes: 4

Views: 3532

Answers (2)

Jakub Arnold
Jakub Arnold

Reputation: 87210

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);

Upvotes: 8

israel de la hoz
israel de la hoz

Reputation: 51

I'm sure you are using flash sockets that use port 10843, and that port is not the one assigned to the app, you need to set:

io.configure(function () {
  io.set('transports', ['xhr-polling']);
  io.set("polling duration", 10); 
});

Upvotes: 5

Related Questions