The while process is divided into 3 steps:
- Creating the Node app
- Setting up the Github Repository
- Setting up the Heroku
Bomus: Configuring your app's config vars
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
npm install
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.
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.
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.