Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js port issue on Heroku cedar stack

I'm running a basic Express app in Node.js and trying to deploy to Heroku. The app works fine locally and I believe my setup with Heroku has gone well up until starting the server where i get the following error:

2011-09-21T16:42:36+00:00 heroku[web.1]: State changed from created to starting
2011-09-21T16:42:39+00:00 app[web.1]: Express server listening on port 3000 in production mode
2011-09-21T16:42:40+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 3000, should be 12810 (see environment variable PORT)
2011-09-21T16:42:40+00:00 heroku[web.1]: Stopping process with SIGKILL
2011-09-21T16:42:40+00:00 heroku[web.1]: Process exited

this is currently all i have in my app.js

app.listen(3000);

I did also run this as mentioned on Heroku's getting started.

$ heroku config:add NODE_ENV=production
Adding config vars:
NODE_ENV => production

I believe I just need to set up the port for production? Thanks.

like image 529
tuddy Avatar asked Sep 21 '11 16:09

tuddy


People also ask

What port does heroku run on?

Heroku expects a web application to bind its HTTP server to the port defined by the $PORT environment variable. Many frameworks default to port 8080, but can be configured to use an environment variable instead.

How do you run NPM install on heroku?

Run the npm install command in your local app directory to install the dependencies that you declared in your package. json file. Start your app locally using the heroku local command, which is installed as part of the Heroku CLI. Your app should now be running on http://localhost:5000/.

What is heroku cedar?

Cedar features a streamlined HTTP stack allowing for advanced HTTP capabilities, heroku run for execution of arbitrary one-off dynos, Procfile and the process model for execution of any type of worker process.


1 Answers

Can you show the entire section of code where you call listen? You should be checking for the process environment variable PORT, not just hardcoding it to 3000. From their docs:

var port = process.env.PORT || 3000;
app.listen(port, function() {
like image 69
Femi Avatar answered Oct 05 '22 22:10

Femi