Deploy Node.js app on heroku

Signup/Signin on heorku

Login from terminal (Make sure you have installed heroku cli –

heroku login

Create app.js

const express = require("express");
const app = express();
const port = 8080;

app.get("/", (req, res) => {
    res.send("Hello Heroku");

app.listen(process.env.PORT || port, () => {
	console.log("listening 8080...");

process.env.PORT this will be provided by heroku server

Test locally by running following command

node app.js
nodemon app.js

If you get any error e.g. module not found you can install those module using npm

npm install <module_name>

To find installed module version

npm view <module_name> version
npm view express version

Create package.json

	"scripts" : {
		"start" : "node app.js"
	"dependencies": {
		"express": "4.17.1",
		"mongoose": "5.13.3",
		"cors": "2.8.5"

Run following command from terminal

git init
heroku create <yournewappname>

Run git commands

git add .
git commit -m 'msg'

#to verify origin
git config -l

#if you are not able to see url and fetch then run git remote add origin 
#git remote add origin heroku_git_url
#git push origin master

git push heroku master

Once app is deployed it will show you an url which you can access publicly from internet.

To see error logs

heroku logs --tail

2 Replies to “Deploy Node.js app on heroku”

    1. you need to install git first if you are using windows you can search for git for windows on google and download git

Leave a Reply

Your email address will not be published. Required fields are marked *