How to host your API on Heroku

How to host your API on Heroku

·

2 min read

You have made your API and tested it on postman or whatever software you use (do recommend me your software, Postman is heavy now). It is also working on your local machine. But you can't keep it hosted on your local machine so you need Heroku.

Heroku is an awesome platform for hosting your APIs. It is a simple thing, you just need to know how to use git?

For that, you can read: Why and How Github?

Set-up

Hope you know how to use git, and if you don't read the post I wrote earlier.

First of all, you need to create an account on Heroku. It is easy just like any other social media account. Now create an app and name it your-project.

Download Heroku CLI

Now you need to download Heroku CLI software on your local machine from where you want to push the API.

Simply download it and install it from the Heroku git page.

Logging to your Heroku account

  • Now open your terminal.
  • Navigate to the project by doing cd which means change directory.
  • Write heroku login and press enter. You will be redirected to your browser to 'Login' to your Heroku account.
  • Press Login and when login is done, it'll show in your terminal.
  • Now it's all set to be uploaded.

Uploading your API

  • Initialize your project with git init.
  • Type heroku git: remote -a your-project and press enter.
  • Now you need to commit the changes to your git by git commit -m 'your message here'.
  • Now do git push heroku master and this will upload your code to heroku.

Adding vars to heroku app

If your app contains any var then you need to add it to your Heroku app. You can do it easily. Follow this:

  • Go to settings of your app on Heroku.
  • Scroll a little and you will see a section named 'Config Vars'.
  • Click on `Reveal Config Vars'.
  • Now you have two sections asking for key and value. Add the same key that you have sed in your code and then add a valid value.

Your app is ready!

Yay! Your API is ready and hosted over Heroku.

If you found this helpful then please share this and do comment your thoughts if you have any.

Chao till the next one.

Priyanshu

Did you find this article valuable?

Support Priyanshu by becoming a sponsor. Any amount is appreciated!