Deploying NodeJS application on heroku

Heroku is a platform as a service (PaaS) that enables developers to build,run,and operate applications entirely in the cloud.


It’s highly recommended to read first these two articles to get full values of this article and also to apply by a real-example


Now let’s start the deployment process by installing heroku-cli
The Heroku Command Line Interface (CLI) makes it easy to create and manage your Heroku apps directly from the terminal. It’s an essential part of using Heroku.
The Heroku CLI requires Git, the popular version control system. If you don’t already have Git installed, complete the following before installing the CLI: git installation Then based on your os install cli tool and you can visit this url and follow the installation steps heroku-cli installation .

To make sure that heroku-cli installed successfully run the following command heroku -v

heroku-cli verify installation

Heroku login

Now login to your account by running the following command heroku login which asking you to click any key to open the browser for authentication.


Click on login button and enter your email password for authentication

heroku login

If you’d prefer to stay in the CLI to enter your credentials, you may run heroku login -i

heroku cli login

Deploying NodeJS App

Now you’re ready to create your first Heroku app:
but before create heroku application in your project directory make sure that you have adding git to your project by running the following command git init

inside your nodejs project directory run the following command heroku create
once you run this command you have created heroku application and you will get two urls one for the deployed app and other url it’s git url for your app.

create heroku application

Publishing your app

To publish your app just run the following command git push heroku master But before push make sure that you have commit your changes to avoid any errors when pushing to heroku master.

publish heroku app

Logging and debug

This is the most important part in your app because you want to see logs to trace and monitor any error appears
so to see logs run the following command
heroku logs --tail

heroku logs

Opening shell

To open shell in heroku and run commands via shell just run the following command heroku run bash

heroku bash


Subscribe to our Newsletter

Subscribe to tech-hour website to get all updates, new articles, new courses and projects. No spam ever. Unsubscribe at any time.