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:
- 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 ...
- 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.