Nodejs-Heroku deploy error


The picture above show some error which occurred during the deployment of the Nodejs app with Heroku.com. There can be two common reason for this

  • First one is the Port
  • Second one is the script associated with ‘Start’

Port

The running port of the Nodejs app may be set for testing of the app. To make port suit with Heroku use the following

app.listen(process.env.PORT || 3000, () => {
  console.log(`listening to ${process.env.PORT}`);
});

Start Script

The second reason of the error can be the start script. Usually you may set the script as follow for development purposes ( with nodemon, which is not required for production).

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon index.js"
  },

Go to your package.json file and replace the start script with node version as follows

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },

and it will work

Published by

Manoj

A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.