Blog iconBLOG

Upload API to Heroku

October 11, 2017

Nejc Ribič
API
Heroku

Heroku is a cloud platform that lets companies build, deliver, monitor and scale apps, as they are saying on their offical website. I also like their moto or main sentence which says, »We're the fastest way to go from idea to URL, bypassing all those infrastructure headaches.« As a matter affect that's quite true. Within next steps you will see how simple actually is to deploy something to Heroku, in my case we will be deploying some simple API made in JavaScript, API will be running on Node.js

Prepare your console

For Heroku to work, first thing you need to do is install Heroku CLI which installation you can find on their official website.

Set up CLI

After successfully installed CLI your console should have command »heroku«.

If you don't have account already, you should go and get one here: https://signup.heroku.com/.

Create simple API

Here is simple code written in javascript

This code contains hard coded array of food names and ids for each food. Code handle some simple GET, POST, PUT requests. As I say this is just some dummy app to demonstrate power of heroku.

Initialize project

Step one: Open console and go to directory where you project is located.

Step two: use command heroku login. Heroku will prompt you to insert you email and password. That is your account email and password

Step three: use command git init. Heroku uses git to deploy files. You can also deploy files manually on the dashboard. What git init does, it initialize local git repository, so git can track versions of your files.

Step four: use command heroku create. Heroku will create project which you can see on your dashboard. Now the project is set online and ready to be deployed.

Step five: use command heroku git:remote –a {your-project-name}. What this command does is connect your local git repository with repository created in cloud.

Add and deploy

Step six: use command git add . Git add actually add files to git, which then track it for you.

Step seven: use command commit –m »message« Now we need to commit everything we changed, so we will be able to send that changes to server in our case heroku server.

Step eight: use command git push heroku master This command send all our files, which we are tracking with git, online.

Step nine: use command heroku open This command open the link which we are hosting on our files, in our case: https://immense-wave-64469.herokuapp.com/ingredients

Step ten: enjoy coding and exploring service of heroku

My Blog

As a student of computer science I learned something very important, when hard days comes, you have to keep working and learning and eventually everything will turn alright!

Categories

API
Heroku