Deployment of NodeJS Application on Heroku Cloud Platform

Jayesh Prajapati
3 min readSep 1, 2020

Hello Everyone,

Today, I’m going to show you how to host Nodejs application to Heroku without any cost.

So, Let’s get Started.

You need to install git cli or Github desktop, both are fine. I prefer Git Cli.

Requirements for hosting Application.

  1. Heroku CLI : here
  2. Git : here

After everything is installed, go to the project folder which you want to host in heroku and create file named Procfile (important : without extension). After creating Procfile, you have to write which command you want to run when the application is hosted. As i am using NodeJS Application, I’ll be using below command like these.

web nodemon app.js

Above command is written in Heroku Procfile.

  • web : Running application in form of website
  • nodemon : tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.
  • app.js : file from where your code execution starts.

Note : Before, creating Procfile was mandatory, but in latest version of heroku, they have made optional. Heroku identifies which project you are hosting so it will automatically run that command.

Our project is ready to deploy on heroku. Let’s go to heroku and setup the repository for deploying the project.

You need to create account in heroku. If you want more functionality and feature, you can buy them from the website. After creating account, you’ll get a screen like this.

I have created many application as you can see. You can create new application using top-right button labelled NEW. Dropdown will open, which have two options : Create new app, Create new Pipeline. We now have to focus on creating new app, So click on Create new app. After submitting, you will get a screen where you have to select name of application and region of hosting. Default region is USA.

Note : You can create only 5 application with free version of heroku.

After creating, it will ask you to create new repository where you can push your code and host the application.

Below is the process for installing and deploying the project on heroku git repository.

Install the Heroku CLI

Download and install the Heroku CLI.

If you haven’t already, log in to your Heroku account and follow the prompts to create a new SSH public key.

$ heroku login

Create a new Git repository

Initialize a git repository in a new or existing directory

$ cd my-project/
$ git init
$ heroku git:remote -a testting-app

Deploy your application

Commit your code to the repository and deploy it to Heroku using Git.

$ git add .
$ git commit -am "make it better"
$ git push heroku master

If you have an existing git repository, then add the url as remote to that repository.

Existing Git repository

For existing repositories, simply add the heroku remote

$ heroku git:remote -a testting-app

When you deploy the application it will automatically start the server and it will return url of your project. You can also find the url for you project on settings page of your application.

You can also add custom domain. But you have to register for premium feature for adding custom domain.

Thank You.

--

--