Reputation: 151
I'm trying to connect to my postgreSQL database on heroku from my express app. This works fine when the express app is also deployed to heroku, but I can't connect to the database when running the express app locally.
const db = require('knex')({
client: 'pg',
connection: ${process.env.DATABASE_URL}?ssl=true,
});
I receive this error: err: Error: self signed certificate
.
How can I solve this?
Upvotes: 1
Views: 540
Reputation: 2452
Another option is to use
connection: {
connectionString: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false },
},
Upvotes: 0
Reputation: 151
So originally I was using a connection string, I changed to using this instead:
connection: {
host: process.env.PRODUCTION_HOST,
user: process.env.PRODUCTION_USER,
password: process.env.PRODUCTION_PASSWORD,
database: process.env.PRODUCTION_DATABASE,
ssl: { rejectUnauthorized: false }
},
when I had ssl: true
it would not work. But then I changed it to the above where ssl: { rejectUnauthorized: false }
and it seems to work fine for now.
Upvotes: 3