How To Deploy Node.js Web Application On Heroku Server

Requirement

 
You must install Node.js, Git (to commit our code in the git repository), and Heroku command-line tools and web storm (optional). Here, I used a web storm for a terminal. You can use any shell terminal for the same.
 
Download links
  1. Node.js
  2. Git
  3. Heroku
  4. Web Storm

Instruction

  • The first point is, create your Heroku account and process all the required verification for code deployment. (Link)
  • Select Node.js as a primary development language whenever you create a new account on Heroku.
  • Before moving forward, check twice that all the required setups are installed. For checking the installation, follow the below command.
  • Please check the below command in your local terminal. I am using Windows OS, so I have a command prompt as my local terminal.

Now, move ahead for the deployment.

S1 > Open your project in a web storm and go to the terminal.
 
How To Deploy Node.js Web Application On Heroku Server
 
S2 > Login to your Heroku account in the terminal. Follow the below command.
 
How To Deploy Node.js Web Application On Heroku Server
 
Enter this command at the Heroku login and hit enter. After that, you need to enter your email address and login password. 
 
S3 > Now, you have successfully logged in with your Heroku account. Before moving ahead, check whether your application is working well local or not. 

How To Deploy Node.js Web Application On Heroku Server

Enter this command in the Heroku local web and hit enter. Generally, when you enter this command, Heroku runs your application in a local server with a port 5000. So, you can check your application in the local server with URL - http://localhost:5000/

How To Deploy Node.js Web Application On Heroku Server

 

Here is my application snap with a local server. URL - http://localhost:5000/
 
S4 > Currently your application is running. So, now we need to stop this application so that we can move ahead with the deployment.
 
To terminate the application with local server press CLTR + C in a terminal and then type Y and hit enter.
 
How To Deploy Node.js Web Application On Heroku Server

S5 > Now, we need to upload our node.js code to the cloud server so that we can deploy that code. We will upload all the code on Git.

First, initialize git in your project directory. For the same type git in it and hit enter.

How To Deploy Node.js Web Application On Heroku Server

S6 > Next, we will add all our changes to the staging area with git add (type this in your terminal) and then commit them with git commit -m "Initing" (type this in your terminal)
Type git add . and hit enter

How To Deploy Node.js Web Application On Heroku Server
 
Type git commit -m "Initing" and hit enter

How To Deploy Node.js Web Application On Heroku Server
 
S7 > Now, we are ready to push to the Heroku cloud, which will host our code.

First, we'll make this a Heroku application with the command Heroku create,

How To Deploy Node.js Web Application On Heroku Server

 

So, our app is created with the name “boiling-reaches-45016” and deploy URL and git URL.
 
S8 > Now, a final step is to deploy all code from git to our Heroku cloud.
 
Write this command to push all code in our Heroku cloud.

How To Deploy Node.js Web Application On Heroku Server
 
Hooray!!! All done. Now, we can access our application with our deployed URL - https://boiling-reaches-46016.herokuapp.com/

How To Deploy Node.js Web Application On Heroku Server
 
NOTE
You can change your domain name with updated DNS from your Heroku accounts.