Step 1:
Create a Heroku account (click here) and also install Heroku CLI (click here) in your local pc.
Step 2:
Make sure Node.js (click here) and Git (click here) installed in your local pc.
To check git version
To check node version
Step 3:
To create (or) import a node repo.
For creating a new repo.
Create a folder mkdir folder-name and move to that folder cd folder-name.
Initialize the git using git init command.
Initialize the node project npm init --y. It creates the default project details.
Make changes in the project as per requirement.
Import existing git repo.
Step 4:
Update your package.json file with include start script, main and engines.
Step 5:
Now in your root directory create a new file with name Procfile Make sure P in Procfile is capital letter and file should not have any extension.
Note: I have used app.js as a filename. Change filename accordingly.
Step 6:
Check process.env.PORT at app listener.
Step 7:
Login in to heroku using CLI command.
Follow the prompts to enter your heroku login credentials
Step 8:
Create a heroku project using heroku create command.
Note: It will create a project with a random name.
Create a project with a specific name
Above step will create a project repo where you can push your changes.
Step 9:
Run below command to set remote repo for your heroku app.
This command will add all file changes to the stage.
This command will push all stage changes to heroku server.
That's all your app will be deployed.
Step 10:
It will open your application in the default browser.
Some useful Heroku commands
Set Environment variables:
Run below command to set an environment variable.
Troubleshooting
To check application logs
For more commands ( click here ). Please comment below for any suggestion.
2 Comments
Thanks for such a useful content ☺
ReplyDeleteThank you so much
Delete