How to deploy a node server on heroku
Heroku is a popular and widely used
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.nameanduser.emailwith 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 masterThis 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 pushcommand to re-deploy. Now, if we go to the URL generated by Heroku, we should see the server up and running.
Free Resources