DEV Community

Cover image for Deploying Nodejs App To Heroku
Moin Akhter
Moin Akhter

Posted on • Updated on

Deploying Nodejs App To Heroku

In this blog we will learn how we can deploy our nodejs app on heroku.

Goals
We will try to deploy our nodejs app.

Prerequisites
You just need to have a heroku account.

Deployment is one of the difficult part for developer.But, heroku made it very easy just few commands and your app deployed.In this blog i will teach you how we can easily deployed our nodejs app on heroku.

How To Deploy On Heroku.

  • First of all login to your heroku account and create an app.
  • While creating app heroku will ask for buildpack which use to build your nodejs app code for nodejs we can select nodejs.

Image description

heroku login
Enter fullscreen mode Exit fullscreen mode

It will take you to browser to login your account.

  • After login add heroku origin.Be remember heroku also uses a git repo on their linux system/machine inorder to store your code after storing into it's repo it will use buildpack to build your code and generate minimized and more compressed version of your code to make it more efficient and faster than make it available to all over the world.You can find heroku remote origin on settings tab.

Image description
You can add heroku origin by using this command.

git add remote heroku https://git.heroku.com/<your_app_name>.git
Enter fullscreen mode Exit fullscreen mode

Here i set heroku origin name as heroku you can also provide any intended name to your heroku origin.

  • After adding heroku origin add your files to staging area and commit your files and than push to heroku origin using this command.
git push heroku <your_branch_name>:main
Enter fullscreen mode Exit fullscreen mode

Above command will not push code to your vcs repo but only heroku's repo.
After that you can also push code to you git repo as well.

  • Once code pushed successfully on heroku origin heroku will start building your app and than deploy your app at the end of logs you will get a deployed url.You can use this url inorder to check whether you app deployed successfully or not.

  • To see logs you can use this command.

heroku logs --tail
Enter fullscreen mode Exit fullscreen mode

NOTE:-
Heroku by default uses main branch to deploy your code from where it should copy code you specifiy like in below command

git push heroku <branch_from_where_to_copy_code>:main
Enter fullscreen mode Exit fullscreen mode

For more detail you can visit https://devcenter.heroku.com/articles/git

That's it, happy coding😉.

Top comments (0)