Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
How to deploy Node.js app on Heroku from GitHub ?
Next article icon

How to deploy Node.js app on Heroku from GitHub ?

Last Updated : 11 May, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

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.


Next Article
How to deploy Node.js app on Heroku from GitHub ?
author
_sh_pallavi
Improve
Article Tags :
  • Technical Scripter
  • JavaScript
  • Web Technologies
  • CSS
  • Node.js
  • Git
  • GitHub
  • Technical Scripter 2020
  • Node.js-Misc
  • Heroku Cloud

Similar Reads

    How to deploy React app to Heroku?
    React is a very popular and widely used library for building User Interfaces. So if you are thinking about deploying your React app to the cloud platform, there are various choices for doing that such as AWS EC2 or Heroku. But for testing your React app, Heroku will be the best option as it is free
    3 min read
    How to Deploy Node.js app on Netlify ?
    Netlify is a powerful platform that simplifies the process of deploying and managing web projects. It provides a wide range of features, including continuous deployment, automatic SSL, serverless functions, form handling, and much more. With Netlify, you can deploy static sites, single-page applicat
    3 min read
    How to Deploy Django application on Heroku ?
    Django is an MVT web framework used to build web applications. It is robust, simple, and helps web developers to write clean, efficient, and powerful code. In this article, we will learn how to deploy a Django project on Heroku in simple steps. For this, a Django project should be ready, visit the f
    4 min read
    Deploying a Django App to Heroku Using Github Repository
    Heroku is a free hosting cloud service provider. We can use our free dynos to deploy our applications on the cloud. The only disadvantage is that it loses all the data once the app sleeps and it cannot handle multiple requests at a time when hosted on free dynos. First of all, to proceed further you
    2 min read
    How to Deploy React App on Netlify Using Github?
    A React App is a web or mobile application that is built using the React library of JavaScript. It helps users create interactive, single-page, and dynamic applications. These applications are built using HTML, CSS, and JavaScript. Deployment of a React app can be done via GitHub, Netlify, or any ot
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences