Skip to content

Instantly share code, notes, and snippets.

@ma-he-sh
Last active February 7, 2018 06:08
Show Gist options
  • Save ma-he-sh/57d9b9308e01a87722039ed3a56b3539 to your computer and use it in GitHub Desktop.
Save ma-he-sh/57d9b9308e01a87722039ed3a56b3539 to your computer and use it in GitHub Desktop.
Heroku PostgreSQL SSL Connection, NodeJS
/**Heroku connection credentials */
var dbconnect = {
dbhost: "",
db: "",
dbuser: "",
dbport: "5432",
dbpassw: ""
}
module.exports.dbconnect = dbconnect;
var remoteDB = require("./config");
const {
Client
} = require('pg')
/**Connection credentials */
const client = new Client({
user: remoteDB.dbconnect.dbuser,
host: remoteDB.dbconnect.dbhost,
database: remoteDB.dbconnect.db,
password: remoteDB.dbconnect.dbpassw,
port: remoteDB.dbconnect.dbport,
ssl: true //- << Ensures SSL Connection
});
client.connect();
client.on('error', (err, client) => {
console.error('Unexpected error on idle client', err);
process.exit(-1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment