1

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?

2 Answers 2

1

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'))
....
Sign up to request clarification or add additional context in comments.

Comments

0

A neat solution would be enabling SSL only for the Heroku server connection. For that add dialectOptions.ssl=true to Heroku environment in config.json file:

  {
"production": {
    "use_env_variable": "DATABASE_URL",
    "dialectOptions": { "ssl": true },
    "logging": false
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.