I used the folder “Desktop/restful” as my REST API folder.

First, create a free Heroku account.

Then, create a new app “morning67890” on Heroku.

Download the Heroku Command Line Interface(CLI)

1
$ brew install heroku/brew/heroku

I copyed all files of my RESTAPI from my old RESTAPI folder to the folder “Desktop/restful”.

Under “Desktop/restful” folder:

1
$ heroku login

Check node version:

1
$ node --version

The noder version shoulde be higher than 10.

Check npm version:

1
$ npm --version

Check git version:

1
$ git --version

Make sure the node.js is runing locally without problem

1
$ npm install nodemon --save-dev

Try to run my API:

1
2
$ node server.js
Error: Cannot find module 'swagger-ui-express'

I should install swagger-ui-express.

1
npm install swagger-ui-express

Try to run my API again:

1
2
$ node server.js
Error: Cannot find module 'joi'

Then install joi:

1
$ npm install joi

After installed swagger-ui-express and joi, server.js runs successfully.

Deploy the app

Create an app on Heroku. You can careate on the Heroku web site or from local computer.

To create the new app locallly, open Terminal and type:

1
$ heroku create

To delete/destroy a Heroku application:

1
$ heroku apps:destroy

Create a new git repository - morning67890 from heroku website

Open Terminal and type:

1
2
3
4
$ cd my-project 
$ git init
$ heroku login
$ heroku git:remote -a node.js-new-website

Deploy your application:

1
2
3
$ git add . 
$ git commit -am "make it better"
$ git push heroku master

That is it. If it doesn’t work, check logs to find out the reasons:

1
$ heroku logs