How to deploy a node server on heroku

Heroku is a popular and widely used PaaSPlatform as a Service container-based cloud platform. It handles application deployment, management, and scaling, making it a popular choice among software developers. Heroku enables developers to perfect their applications rather than worrying about the architecture that executes them. As a result, we can invest more time in the development process to ensure a smooth and high-quality user experience.

Installation

The easiest way to install Heroku CLI is via the npm package, as shown in the command below:

$ npm install -g heroku 

Example

Execute the following commands to deploy a backend server on Heroku:

  • Log in to a Heroku account using the command:

    $ heroku login -i
    
  • Configure a git account with the following commands:

    $ git config --global user.name "your_username"
    
    $ git config --global user.email "your_email_address@example.com"
    

    Note: Replace the strings user.name and user.email with our own Git account email ID and username. Furthermore, do not remove the double quotes from the inputs (e.g., "your_username") while entering the account details.

  • Set up a Git project in the app’s root directory using the following command:

    $ git init
    
  • Next, add all the project files using following the command:

    $ git add .
    
  • Then to commit the changes to the Git project, run the following command:

    $ git commit -m "Initial commit"
    
  • Next, run the following command:

    $ heroku create
    

Note: This creates a new application on Heroku and an associated empty Git repository.

  • Now, we push the code to the remote Git repository that we have just created using the following command:

    $ git push heroku master
    

    This will push the code to the Heroku servers and set up our app’s dependencies on them. When code changes occur in our app, rerun the git push command to re-deploy. Now, if we go to the URL generated by Heroku, we should see the server up and running.

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved