If you have a Nodejs server that you want to upload to heroku, here is a guide you can follow. I hope this helps a beginner out there.
Package.json
Firstly, we need to add the following to our package.json
.
{
"name": "session",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": { // ==> heroku engine
"node": "16.15.0"
},
"scripts": {
"start": "node ./src/server.js" // ===> start command
},
"keywords": [],
"author": "",
"license": "ISC"
}
1. Heroku CLI
I hope you already have the heroku cli installed on your local machine.
2. Heroku Login
Login to your heroku account using terminal.
heroku login
3. Create Heroku app
Using the terminal, create a heroku app;
heroku create <app-name>
4. Add Heroku app
You need to set your online (cloud) Heroku app as a remote git repository for your nodejs server.
heroku git:remote -a <app-name>
5. Environmental variables
If your app has .env
file, then you would add that in Heroku manually, Find the section named Config Vars
and click on Reveal Config Vars. Here you will add the same key and value pairs from the .env file you used locally. You can see mine below with the values blurred out.
6. Push
Now, we are ready to push our nodejs server to Heroku
git push heroku main
Thank you, please follow me
Top comments (0)