Deploy NodeJS App in Heroku

This tutorial describes the steps to deploy nodejs app in Heroku.

  • Download and install the Heroku CLI.
  • cd into the project folder e.g cd notesapp
  • Login to the heroku using the command: heroku login
  • Initialize git repository (if not already initialized) by using the command: git init
  • Assign remote directory to the git by using the command: git remote add heroku <URL Here>
  • To remove existing remote origin URL, use the command: git remote remove origin
  • To update/reset remote origin URL, use the command: git remote set-url origin git://
  • To note the changes in working directory run the command: git add .
  • To save your changes in the local repository with comment, run the command: git commit -am “make it better”
  • To push the changes to the remote directory, run the command: git push heroku master

TIP: If you want to force the changes from local repository to the remote directory then use the following command (not recommended though):

git push –force heroku master

If you get port error, then try to change the app.listen method as follows:

app.listen(process.env.PORT || 5000, function(){    
   console.log('Server is running at port : ' + 5000);

Leave a Comment

Your email address will not be published. Required fields are marked *