DEV Community

Cover image for Deploy PostgreSQL in Node.js to Heroku for beginners

Deploy PostgreSQL in Node.js to Heroku for beginners

Giovanna Aveiro
Fresh full stack developer. She/her. Founders and Coders alumna #19
Updated on ・2 min read

During my time at Founders and Coders, we had to use Heroku to deploy our Node + PostgreSQL projects quite a few times. Because it can be daunting at first, I put together this step-by-step based on their graphic user interface. It is quick and straight to the point. Questions and contributions are welcome!

Deploy your project

Signup/Login to Go to New > Create new app to start. Add name, region and hit Create app. Choose GitHub as a deployment method under the 'Deploy' tab, search for your repo to connect:


on the same tab, click enable automatic deploys with the master branch for your future deploys. For the first install, hit Deploy Branch in 'Manual deploy' section to deploy your app:


Important to notice that after deployment, Heroku will run the 'start' script in your package.json to start your application. Make sure it is correct.

"script": {
    "start": "server.js"

Deploy your PostgreSQL database to Heroku

Once your app is up you should see the message below:


Go to 'Resources' tab and search for Heroku Postgres add-on, then select the Hobby Dev - Free version and hit Provision to confirm.


Back to 'Resources' tab, you can see your current database clicking on Heroku Postgres. You should see in a new tab something similar to the below image, indicating your database is empty:


Connect to the database

Heroku will generate a DATABASE_URL that you can use to connect to your production database. You can find this under 'Settings' back to the project tab in Reveal Config Vars with key 'DATABASE_URL'.

Important: If your project/database depend on API keys or tokens, add them in your config vars.

Connect to it via psql/pgcli copying and pasting the url in your terminal and then running you init.sql file:

//in psql


\i database/init.sql;

Some extra tips

  • You can view more information about the database by accessing it from 'Resources' and navigating to 'Settings' > View Credentials;
  • You can add collaborators via Accesstab;
  • View logs in More;
  • You can delete projects from Heroku in 'Setting' at the bottom of the page.

Discussion (4)

joepock123 profile image
Joe MJ

This is really helpful thank you!

glrta profile image
Giovanna Aveiro Author

Thank you for the feedback, Joe!

bianoraraujo profile image
Bianor Araujo

Great post! Thanks

tomaszwagner1 profile image

Great read, thank you, Gio!

Forem Open with the Forem app