I followed the steps at: https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction
When I ran heroku local it couldn't connect - I saw that it was using the process.env.DATABASE_URL and got it to my local .env file using: https://devcenter.heroku.com/articles/heroku-local
But it still wouldn't connect, I've added a console.log to see the error:
"error: no pg_hba.conf entry for host "62.90.xxx.yyy", user "username", database "password", SSL off"
What now?
After a lot of searches it turns out that added 'pg.defaults.ssl = true' solves the problem for me while allowing me to stay as close as possible to the sample provided by Heroku.
Here is my code
const cool = require('cool-ascii-faces');
const express = require('express')
const path = require('path')
const PORT = process.env.PORT || 5000
const pg = require('pg');
pg.defaults.ssl = true; //this is it!!!
express()
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
....