DEV Community

Cover image for How To Quickly Deploy Node Js App To Heroku
Sanket Patel
Sanket Patel

Posted on • Originally published at

How To Quickly Deploy Node Js App To Heroku

This tutorial will cover how to deploy the Node.js project to Heroku - the cloud application platform. We will have our application up by running few commands.

Assuming you have any node.js app that you want to publish. If not, I have listed the steps in this tutorial. The codesandbox for the same is here to set up the basic app.


  • Git

    • To use the Huroku CLI we will need to have the Git installed in the machine, so make sure you have it.

You can check if it is already installed or not using

    $ git --version
    git version
  • Node 8+
  $ node --version
  • A registered account at
    • Please sign up and verify your email address, if you haven't.

Initialize the Git for the project (if it isn't)

If your project is the git repository itself then move to install heroku

$ git init
Initialized empty Git repository in your-project-path/.git/

Create a .gitignore file to ignore node_modules

$ echo node_modules > .gitignore

Commit the files to git repository

$ git add -A

$ git commit -m 'initial commit'
[master (root-commit) e79168d] initial commit
 4 files changed, 2047 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 index.js
 create mode 100644 package.json
 create mode 100644 yarn.lock

Install Heroku

Download and install the Heroku CLI as per your platform.

Check if it is installed by checking version.

  $ heroku --version
  heroku/7.24.3 win32-x64 node-v11.14.0

Login to Heroku

heroku login command will ask us to open a browser using pressing any key. Then you can login in browser and the terminal will catch it. Isn't it cool!

$ heroku login
heroku: Press any key to open up the browser to login or q to exit:
Opening browser to
Logging in... done
Logged in as

Create a Heroku app

Create the app using command heroku create <optional-app-name>

$ heroku create nodejs-tutorial-one-3sanket3

Creating ⬢ nodejs-tutorial-one-3sanket3... done |

Make sure the package.json of your project have a start command

"scripts": {
    "dev": "nodemon index.js", <-- for local development purpose
    "start": "node .", <-- Heroku will use to start the application
    "test": "echo \"Error: no test specified\" && exit 1"

Note: If you want to use start command for some other task, you can create a Procfile . It will tell Heroku which command to run while starting the application, as explained here.

Deploy the code

$ git push heroku master

If everything goes fine you should see the last part of the command output as below. It contains the URL at which your app is deployed.

heroku deployment output

Check deployment logs

Using heroku logs --tail command, you can check logs of deployment. It will be updated realtime so you can keep it open while deployment, in another terminal tab/window keep your eye on it.

Ref :
Cover Photo by Rakicevic Nenad from Pexels

Top comments (4)

rohovdmytro profile image
Rohov Dmytro


This is what I was doing before migrating to use dokku and Digital Ocean.

3sanket3 profile image
Sanket Patel

I would love to know the reason for the migration, if you can share.

rohovdmytro profile image
Rohov Dmytro

There was a reason definitely but I am not sure.

I might think that I need to run couple of simple websites and it was much cheaper to di via dokku with no downsides for my usecase.

hammadsiddiqui profile image
Hammad Siddiqui

An addition of mLab add-on is always helpful since most node apps may require a DB