Skip to content

Instantly share code, notes, and snippets.

@talk2sohail
Created July 19, 2020 13:32
Show Gist options
  • Save talk2sohail/3105a4847aa42b9882d18817b031c06f to your computer and use it in GitHub Desktop.
Save talk2sohail/3105a4847aa42b9882d18817b031c06f to your computer and use it in GitHub Desktop.

How To Deploy Node app in Heroku via Github

The while process is divided into 3 steps:

  1. Creating the Node app
  2. Setting up the Github Repository
  3. Setting up the Heroku

Bomus: Configuring your app's config vars

Creating a Node app

To save the time of creating a new Node app, we will outsource the app from express-generator. if you are using the node version >= 8

npx express-genrator myapp

and the change the directory to your app.

cd myapp

Installing Dependencies

npm install

Setting up the Github Repository

Create the repo of your own. It is fairly easy process. You can create your own repo here.

Having done that, you must push all your local repo code to the new cool repo you just made out of the box! I will be adding another file below to make sure go through this process easily.Good luck.

Setting up the heroku

Heroku will be providing us the url which we can share to others so that they can access our app from anywhere on the earth. to make that happen we need to create our app on heroku side as well. Log in to your console here and head out to create a new app of ouw choice. The name you are going to choose will be domain of your url.

After successfull login, it will take you to the console. Click on the Github option given in the Deployment Method.

Search the your repository in the search bar and repository name to want to deploy.

You will be given the option for continuous deployment. I think this is the best thing about automating the whole deploying process ;-) If you keep this on, your code will be automatically be deployed without repeating the whole process, when you push some new code to your repository.

And below you will see a button along with a select options to deploy the particular branch of your choice. This may come handy when you want separate your production and testing code.This might take seconds depending on the size of your app.

And Voila!! Your app is deployed.

BONUS: Configuring your app's vars

I am pretty sure you won't be uploading your .env file to your Github repo, then how come your app will access the all config keys set in the .env file?( I am talking about the process.env variables used in the code) Heroku will help us here. Goto Settings>Config Vars section. Click the button Reveal Config vars and your key/value pairs ( this might your Database, acccess token credentials etc).

You can surely do this from your Terminal/Heroku CLI as well.

After setting this keys value, your app will automatically be redeployed using the same repo you selected earlier. And You are Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment