Skip to content

An example of working app with node, express, and sequelizer on deployed Heroku with PostgreSQL db.

Notifications You must be signed in to change notification settings

b1994mi/heroku-pgsql-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intro

This is somewhat a boilerplate for deploying an app to Heroku using node, express, pg, and sequelizer. I have successfully deployed this to heroku and the db connection working.

Reminder

  • Make sure that .gitignore is present and inside it contains:
/node_modules
npm-debug.log
.DS_Store
/*.env
.gitignore
  • Make sure that package.json on your root project folder have "start": "node index.js" on the "scripts" property, otherwise Heroku will not start the app.
{
  ...
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  ...
}
  • Make sure you have PostgreSQL added on the add-on list before pushing your app to Heroku.

  • Last but not least, make sure your app listens to the correct port in the index.js file:

const port = process.env.PORT || 8000
app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
})

Tutorials that I followed

  1. Express Sequelize Heroku Postgres Configuration Success

Following this article, you will need to change the config.json file generated by sequelize-cli init so that it looks like this:

{
  "production": {
    "use_env_variable": "DATABASE_URL"
    , "dialect": "postgres"
    , "dialectOptions": {
      "ssl": true
    }
  }
}

To make sure that the db has synced, run heroku psql and inside that psql run \dt to list all the tables. But, after running heroku logs --tail, I soon found out that the app won't run and had to follow article No. 2.

  1. 'Self signed certificate' error during query the Heroku hosted Postgres database from the Node.js application

After following article No. 1, I had an Error: self signed certificate. It turns out that I need to set the ssl: { rejectUnauthorized: false } on config.json. So, I need to change the config.json file again into:

{
    ...
    , "dialectOptions": {
      "ssl": { "rejectUnauthorized": false }
    }
    ...
}
  1. Is it safe to set rejectUnauthorized to false when using Heroku's Postgres database?

Just to make sure what rejectUnauthorized: false is, I searched it and found out that Heroku does not support client-side certificate validation to its Postgres.

Deployed Version

I have no deployed version for this app to conserve my Heroku app count, but I asure you that I have successfully deployed this "template" app ;)

About

An example of working app with node, express, and sequelizer on deployed Heroku with PostgreSQL db.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published