Skip to content

Instantly share code, notes, and snippets.

@cyjeff
Last active March 21, 2021 06:33
Show Gist options
  • Save cyjeff/a438e591540453c5815d0165a61ac7bf to your computer and use it in GitHub Desktop.
Save cyjeff/a438e591540453c5815d0165a61ac7bf to your computer and use it in GitHub Desktop.
SSL setting for Knex.js to postgreSQL on Heroku
const knex = require("knex");
const parse = require("pg-connection-string").parse;
// Parse the environment variable into an object containing User, Password, Host, Port etc at separate key-value pairs
const pgconfig = parse(process.env.DATABASE_URL);
// Add SSL setting to default environment variable on a new key-value pair (the value itself is an object)
pgconfig.ssl = { rejectUnauthorized: false };
const db = knex({
client: "pg",
connection: pgconfig,
});
module.exports = db;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment