To deploy Node.js application to Heroku, it is a piece of cake, we do not need to do anything, just create our environment variables on Heroku platform and push the whole application to GitHub that is everything.

 

Before pushing our Job Application to GitHub, we need to make sure that the environment file “.env” that store all secret stuffs in there will not be pushed to GitHub. To prevent this from happening, we have to create a .gitignore file to ignore .env file and other files if we want.

 

// .gitignore

# dependencies
/.env
/node_modules

 

The above .gitignore file will also ignores all installed packages in node_modules folder created by NPM package manager. Heroku will not need those installed packages because it will read the package.json file in our Job Application package and it will install everything we need for the application to run on Heroku platform.

 

First of all, we need to create a repository on GitHub and write on Terminal window as below:

 

$ git init
$ git remote add origin https://github.com/Sokhavuth/khmerweb-job.git
$ git add .
$ git commit -m "First commit"
$ git push origin master

 

All files will be pushed to the repository https://github.com/Sokhavuth/khmerweb-job.git except .env file and node_modules folder.

 

On Heroku platform we need to create an app in which we have to create our environment variables in the app Settings. After that, we can connect our Heroku app to our GitHub repository by clicking Deploy > GitHub > Connect > Automatic Deploy > Deploy Branch. Heroku will copy everything it needs to build and install all packages following the information in the package.json file to install our Job Application on its platform.

 

GitHub: https://github.com/Sokhavuth/khmerweb-job

Heroku: https://khmerweb-job.herokuapp.com