Heroku + Node.js + Sequelize + PostgreSQL – How to Deploy Node.js Web Application with PostgreSQL on Heroku platform using Heroku CLI


Heroku is a platform as a service (PaaS) that help us to build, run, and operate applications entirely in the cloud. So in the tutorial, we show you how to deploy Node.js WEB application with PostgreSQL in Heroku.

Related posts:
Sequelize ORM – Build CRUD RestAPIs with NodeJs/Express, Sequelize, MySQL
Heroku + SpringBoot Deployment example – How to Deploy SpringBoot + PostgreSQL on Heroku platform with Heroku CLI


– Heroku
– PostgreSQL
– Node.js
– Sequelize
– Git


We deploy a Node.js Web Application with PostgreSQL to Heroku platform:

– Heroku PostgreSQL ->



– Node.js RestAPI ->



Setup Heroku CLI
Download & Install Heroku CLI

For detail go to the Download Heroku CLI

– Install Heroku CLI on Linux:

-> Details:

Login to Heroku

Use heroku login cmd to login:



Add Heroku SSH keys

– To check your key was added, run heroku keys
– If your key isn’t there, you can add it manually by running heroku keys:add


Create Simple Node.js Web Application
Create simple Node.js Web Application

Create package.json file:

-> Process command:

-> It creates a package.json file with below content:

– Install Express & Body-Parser:

npm install express body-parser --save

Implement simple Node.js Web App

Inside root folder, create a file server.js file:

Configuration to Run on Heroku
Specify the version of Node.js

To run your application on Heroku, specify the version of Node.js:

Create Procfile

Heroku use a Procfile to start your app. Inside the root folder, create a Procfile with below content:

– If no Procfile exists for a Node.js app, we will attempt to start a default web process via the start script in your package.json:

– The command in a web process type must bind to the port number. -> We create a .env file, inside a root directory.
Then define the application port in it:

Run App Locally

Use below cmd ->


Deployment on Heroku
Create a Git Repository

Go to Git Account, create a Git Repository:


– Keep build artifacts out of git by creating a .gitignore file that looks something like this:

– Add all of the code to Git by running these commands:

Create a new Heroku App

– Use the below commandline to create Heroku App:
heroku create


-> It creates a new Heroku App with random name: shrouded-island-81150


– We can rename the app using the cmd ->

$ heroku apps:rename --app oldname newname

-> Details:




– Now deploy your code by commandline:

git push heroku master

-> Logs:

-> Visit the app’s URL by running this command: heroku open



Deploy Node.js Web Application with PostgreSQL on Heroku
Heroku Attach PostgreSQL Database

– Attach a PostgreSQL database to your application by cmd:

heroku addons:create heroku-postgresql


– List the configuration variables by cmd: heroku config & heroku pg

Update Node.js App accessing PostgreSQL with Sequelize

– Install Sequelize:


-> Now package.json ->

– Setting up Sequelize MySQL connection ->

Create ./app/config/env.js file:

Setup Sequelize-MySQL connection in ./app/config/db.config.js file:

– Create Sequelize model ./app/model/customer.model.js ->

– Define Customer’s routes in ./app/route/customer.route.js file ->

– Implement Customer’s controller in ./app/controller/customer.controller.js file ->

– Update server.js ->

Re-deployment Nodejs on Heroku

– Add the change to Git Repository ->

-> Deploy code:

git push heroku master ->


– Heroku PostgreSQL ->



– RestAPIs requests ->


– Logs $heroku logs --tail ->



By grokonez | December 19, 2018.

Related Posts

Got Something To Say:

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