How to deploy your Node API on Heroku
Heroku is a cloud platform that lets companies build, deliver, monitor and scale apps — we’re the fastest way to go from idea to URL, bypassing all those infrastructure headaches.
One beautiful thing about hosting your API is that it’s free but you’ll get .herokuapp
appended to your URL. Heroku has a lot of addons for your project ranging from data stores to monitoring to logging to caching etc.
There are at least two ways to host your API on Heroku.
- Heroku CLI
- GitHub integration
Heroku CLI
Create an account on Heroku
Install Heroku globally on your local machine using npm npm install -g heroku
Check the version installed heroku --version
After successfully installing Heroku locally, you need to login into heroku with heroku login
, you’ll be prompted to press any key to open up in a web browser
After a successful login, create a Nodejs App (make sure Git is initialized and all changes are committed) or clone https://github.com/Rexben001/heroku-node-app.git
From the root directory, run heroku create <preferred-project-name>
to create an App on Heroku
Deploy the App to Heroku git push heroku master
Your CLI output should look like this. You can get the URL of your API from the area circled in the image
GitHub integration
The advantage this approach has over the Heroku CLI is that you can activate automatic deployment, your app will be deployed anytime there are any changes in your main branch on GitHub.
Create an account on Heroku
Create a Nodejs project and push your code to GitHub
Go to Heroku and create an App
Click on Deploy Tab
Click on Connect to GitHub
Search for the GitHub repo
Click on Connect
1. Select the branch you want to deploy and click on
Deploy Branch
to deploy a particular branch2. Select a branch you want to deploy and click on
Enable Automatic Deploys
to activate automatic deployment, it will look for any changes in the branch and deploys it.
After successfully deploying a branch, you can click on View to see the deployed App.
Happy Deploying!!!!