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


create project and verify with normal url

mkdir /var/www/html/myproject

vim index.html

<h1>Hello World</h1>

vim index.php



Create server block conf file

vim /etc/nginx/conf.d/myproject.conf

server {
  listen 8082 default_server;
  server_name _;

  index index.php index.html;

  root /var/www/html/myproject;

  location ~ \.php$
      include snippets/fastcgi-php.conf;
      fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

Test nginx configuration

nginx -t

restart nginx

sudo service nginx restart
sudo systemctl restart nginx

For Laravel Project
Specify path till public directory