Tips on deploying to Heroku

A few days ago I’ve built my first backend project and successfully deployed it to Heroku. That time I strictly followed the instructions given in “Get Set for our Back End Development Projects” challenge. But my second project (request header parser) I decided to write from scratch, as I thougth that Clementine.js boilerplate gave too much unnecessary functionality for a so simple task. My new app worked fine when run at cloud9, but at Heroku it didn’t. After checking logs I found that I did following mistakes, that prevented my app from working:

  1. I hardcoded port number (app.listen(8080, function() { ...), while Heroku assigns the port number through evironment variable, so the correct code would be like this: app.listen(process.env.PORT || 8080 ...
  2. Heroku requires a script thats starts up the app, specified in package.json:
    ... "scripts": { "start": "node your-app-name.js" }
    After adding this lines my app started to work correctly.

If you are running linux -t will show the log in realtime when the app starts “running” and will show errors.

thank you! Your advices helped me deploying my first app! :smiley:

1 Like