Skip to content

Instantly share code, notes, and snippets.

@mattonit
Created November 20, 2017 08:47
Show Gist options
  • Save mattonit/ae6a8fa2c2cf9cca8eed314ba62c7ee7 to your computer and use it in GitHub Desktop.
Save mattonit/ae6a8fa2c2cf9cca8eed314ba62c7ee7 to your computer and use it in GitHub Desktop.
Hapi PgSQL Connect
'use strict'
const { Client } = require('pg');
const Database = {
register: (server, options, next) => {
const db = new Client({
user: 'db_user',
host: 'host',
database: 'db_name',
password: 'db_pass',
port: 5432, // default PgSQL port
ssl: true // force SSL
})
db.connect()
server.app.PgSQL = function(){
return db;
};
next();
}
}
Database.register.attributes = {
name: 'Database',
version: '1.0.0'
}
module.exports = Database;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment