googleads
How To Deploy NodeJS App to Heroku | Heroku Deployment - DevOps
preloder
DevOps

How To Deploy NodeJS App to Heroku

Today, I am going to demonstrate how to deploy a Node.js application on Heroku with a sample example, before getting into the steps let’s understand what is heroku.

What is Heroku?

Heroku is a cloud platform as a service supporting several programming languages that is used as a web application deployment model. Initially, it supported only the Ruby programming language, but now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go. For this reason, Heroku is said to be a polyglot platform. It lets the developer build, run and scale applications in a similar manner across all the languages.

Sample example to deploy a NodeJS app with heroku

Note: Heroku Node.js support will only be applied when the application has a package.json file in the root directory or application.

Prerequisites:

  • Node.js and npm installed.
  • Node.js application.
  • Heroku account.
  • Heroku CLI.

 

Create NodeJS app:

Following command will create the NodeJS app folder structure

Step 1:  $ npm install -g express-generator
Step 2: express application_name

Once the above commands are done, the package.json file will available inside application_name

The generated package.json file looks like this:

    

 

Specify the version of node:

  1. The version of Node.js that will be used to run your application on Heroku, should also be defined in your package.json file. You should always specify a Node.js version that matches the runtime you’re developing and testing.
  2. If you not mention Node.js version, heroku will take default latest version and it will run your application on the node engine. But in any case we need to define the Node.js version is good choice.

 

package.json file will look like this:

 

 

Build your app and run it locally:

Step 1 : Run the npm install command in your local app directory to install the dependencies that you declared in your package.json file.

      

 

Step 2 : Start your app locally using the heroku local command, which is installed as part of the Heroku CLI.

  

 

Step 3: App should now be running on
       

 

 

Deploy your application to Heroku:

After you commit your changes to git, you can deploy your app to Heroku

Step 1: 

 

Initialized empty Git repository in /home/ken/Desktop/Nodejs/application_name/.git/

Step 2:

 

Step 3:

 

Step 4:

 

Step 5:

 

Step 6:

 

Unlike other service providers, Heroku will reduce the manual configuration and package installations. With help of Heroku, we can completely get the required installed files and configurations and With just few steps we can easily run the application just by mentioning the Root directory, dependency files and the version of app.

The following two tabs change content below.

Ken

Senior Full Stack Developer having 3 years of experience in Web development arena , Expertise in MEAN stack, Python, Javascript, Angular. And, This freaking humor bomb loves to involve himself in playing auspicious Games but Once you reach him, he ll always make sure to light up your terrific days with laughter's.

One thought on “How To Deploy NodeJS App to Heroku”

Leave a Reply

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

[contact-form-7 id="120788" title="Web Page Form"]

Schedule Your Call