How to Deploy Your Node.Js App to Heroku.

How to deploy your Node.js API to Heroku in 5 steps.

Moses Esan
The Startup
2 min readNov 23, 2019

--

In this tutorial, I will be laying out the steps required to deploy a Node.js app to Heroku. For this example, I will be deploying the authentication API built in my previous tutorial.

Requirements

  1. Heroku account, sign up for free
  2. The Heroku CLI
  3. GitHub account

Setup GitHub Repo

If your project is not set up to use git, run the commands below

Step 1: Add Procfile

Add a Procfile to the root directory to declare the command to be executed to start the server.

Update the Procfile with the code below. This declares a single process type web and the command needed to run it.

Commit your changes

Step 2: Log in to your Heroku account

Step 3: Create a Heroku App

Step 4: Set Environment Variables

Run the commands below to set the environment variables

Step 5: Deploy

Run the code below to deploy your app

The application is now deployed. Ensure that at least one instance of the app is running:

Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website as follows:

TROUBLESHOOTING

If for some reason, something went wrong, use the command below to check the log.

That’s all folks!

That’s all folks!

Related Tutorials

  1. How to Build a Node.js Authentication API with Email Verification, Image Upload and Password Reset Using JWT, Passport.js, and Sendgrid.

--

--