Hosting RESTful API On Heroku Server

A warm welcome to all readers!

This blog explains how you can host your RESTful API created using MySQL and node.js.  If you don't know how to create RESTful API, read my previous article here.

Heroku is a platform that allows us to host a maximum of five  applications without any charges. It is very simple to deploy and scale our node.js application to the Heroku Server. In this demo, I am using command line to deploy the application on Heroku.

Follow the steps shown below. 
  • Initialize your current project as git directory, using the following command

         cmd>git init 

         
 
         It will create your directory as git repository.
  • Login using Heroku Account.

         cmd>heroku login

        
      
        Now, by writing the above command, I am logged into my Heroku account.
  • Creating application on heroku server

    cmd>heroku create name of the application



    The " heroku create nodejsdemoapi " command will create a directory named as nodejsdemoapi on Heroku Server, in which, we can host our node.js or any other application that we want to host.

    So, we are almost all done. So far, we have installed Heroku Toolbelt for command line, logged into Heroku from command line, and created application on Heroku Server. Now, we are good to go and ready to deploy our node.js application to Heroku Server, using git commands.

    Well, before adding pages to the Server, we have to include node_modules to the ".gitignore" file, as shown below.

     
  • Push pages to Heroku Server

    cmd>git add

    It will add each and every file in the directory to the Server.



    cmd>git commit -m "initial commit"

    This will commit all the changes.



    cmd>git push heroku master

    Finally, it will push all the pages to the Server.



    The highlighted link is the URL of our just hosted application on Heroku Server.


    Testing one of the URLs. 
         
Ebook Download
View all
Learn
View all