Hosting NodeJs Application on Heroku Platform using Heroku CLI

Search for a command to run...

No comments yet. Be the first to comment.
You've done it. I've done it. We've all done it.

Your AI Agent Has Amnesia. ByteRover Fixes It — Without Vectors Let's see how to built a customer support agent that remembers everything — using plain markdown files, BM25 search, zero embeddings, a

My GenAI cohort kicked off today, and what a first day! Right away we were reminded that AI isn’t magic — at its core, models like Generative Pretrained Transformers (GPT) are doing one simple thing:

Hello Folks👋, I Recently got Graduated🎓 in 2020, yep in the Pandemic. We all hit very hard by this Corona Pandemic and we all got stuck at home for very long. We all realize the Importance of Socializing, Fitness (Physically as well Mentally), Diet...

So after learning the basic commands of git in our previous section, let's see Git in action. If you already have a project to track your files then you can skip this section and if not then continue. Initializing a Repository from Non-existing Dire...

In this blog, we will learn how to Host NodeJs Application on Heroku Platform using Heroku CLI. No need to leave your terminal or code editor, all from the terminal itself, huh?, pretty cool, right? Let's see how we can achive this.
Heroku login is required once. Enter below command in your terminal and follow up the prompt window and Authorize
heroku login
Add The version of Node.js to your package.json file:
"engines": {
"node": "10.x" // replace x with your node version like 10.16.2
},
create a Procfile file inside the root directory of the project and add the below code in it
web: node app.js
By default, Heroku will look into our package.json file under the scripts section and grab start command. Sometimes we won't have that defined or it will be different from what we want the server to execute. We can specify the exact command we want by creating a Procfile file.
Specify a unique name for your application, this name should be globally unique.
heroku create <app-name>
example:
heroku create todo-app-rest-backend-nodejs
If you got random app name or if you want to rename your Heroku app then use the below command to achieve it from the terminal itself.
heroku apps:rename <new-app-name> --app <old-app-name>
heroku local web
git push heroku master
Once the build and deployment is successful you will receive the url of the Hosted Application in your terminal.
Use below command for each environment variable to set all of your env variables and you are done.
heroku config:set <environment-variable-name>=<value>
heroku config:set GITHUB_USERNAME=joesmith
heroku config:set PORT=3000
Congratulations!! You had successfully learned how to host the NodeJS application on Heroku Like a PRO