How to deploy Node.js app on Heroku from GitHub ?
Last Updated :
11 May, 2022
In this article, we will be looking at how to deploy your Demo Node.js app to Heroku. At the end of this article, we will have a basic Hello World app running on a public domain that can be accessed by anyone. The Node must be installed on your machine. Refer to this article How to install Node on your machine.We are also going to use Github account.
Step 1: Installing Nodemon and Express Module in the project folder
Installing express module:
npm install express
Installing nodemon module:
npm install nodemon
Step 2: Creating package.json file in the project folder by using npm init command:
These two commands are important for running and dynamically running the code after changes made in your Node.js app respectively.
"start": "node app.js",
"dev": "nodemon app.js"
Configuration of package.json file
{
"name": "demoapp",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.6"
}
}
Project structure:
app.js
JavaScript
// Importing express module
const express = require('express');
const app = express();
// Getting Request
app.get('/', (req, res) => {
// Sending the response
res.send('Hello World!')
// Ending the response
res.end()
})
// Establishing the port
const PORT = process.env.PORT ||5000;
// Executing the server on given port number
app.listen(PORT, console.log(
`Server started on port ${PORT}`));
Execution command:
nodemon app.js
Console output:
Browser output: Now, if we open http://localhost:5000/ in your browser, we will see this:
We have just created a basic Node.js app.
Deploying Node.js app
Step 3: Pushing the Node.js app to GitHub: Create a new Repository on GitHub by clicking New Repository on the tab. GitHub will create a repository and also give some instructions to clone the project.
In the command prompt, run the below commands for pushing your project to the new Repository.
git init
git add .
git commit -m “first commit”
git push — set-upstream origin master
git remote add origin https://github.com/pallavisharma26/DemoApp
git push — set-upstream origin master
- Now if you open GitHub and refresh the repository, you should be able to see the code that you have added recently.
Step 4: Deploying the Node.js app to Heroku
- Create a free account on Heroku
- After completing all processes now login to your account.
- Click on the “Create new app”.
- Open the Deploy tab and scroll to the “Deployment method” section of the tab.
- Select GitHub as a method. It will show a “Connect to GitHub” option where we add provide our GitHub repository. If you are doing it for the first time, Heroku will ask permission to access your GitHub account you have to permit that.Here, you can search for your GitHub repository and click connect for creating a connection.
- After that, the Deployment section will show up where you can select pick them up and deploy or Manual Deployment, click Enable Automatic Deploys.

- Now we have to tell Heroku that our app is a NodeJS app.
- Open the Settings tab scroll down and click "Add buildpack”.

- Select NodeJS from the options and click Save changes. Now, go back to the Deploy tab, and click Deploy Branch at the bottom.
- Heroku will take the code and host it. Open the Activity tab and there you can see the progress:

- Now open the Setting tab scroll and look for Domain. We can see a URL if we copy paste and run in the browser, we can see our Deployed App.
This is a straightforward app, we can deploy any advanced project on Heroku without installing it on our desktop or machine.
Similar Reads
JavaScript Tutorial
JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development
Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
React Interview Questions and Answers
React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
JavaScript Interview Questions and Answers
JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as
15+ min read
React Tutorial
React is a JavaScript Library known for front-end development (or user interface). It is popular due to its component-based architecture, Single Page Applications (SPAs), and Virtual DOM for building web applications that are fast, efficient, and scalable.Applications are built using reusable compon
8 min read
Decorators in Python
In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality. Decorators are
10 min read
AVL Tree Data Structure
An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The absolute difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of
4 min read
Sliding Window Technique
Sliding Window Technique is a method used to solve problems that involve subarray or substring or window. The main idea is to use the results of previous window to do computations for the next window. This technique is commonly used in algorithms like finding subarrays with a specific sum, finding t
13 min read
Domain Name System (DNS)
DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w
8 min read
What is a Neural Network?
Neural networks are machine learning models that mimic the complex functions of the human brain. These models consist of interconnected nodes or neurons that process data, learn patterns, and enable tasks such as pattern recognition and decision-making.In this article, we will explore the fundamenta
14 min read