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.
- 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}`)
})
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.
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 }
}
...
}
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.
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 ;)