Skip to content

Instantly share code, notes, and snippets.

@ktilcu
Last active May 10, 2018 16:35
Show Gist options
  • Select an option

  • Save ktilcu/87b18e3be9ad560151708f6efbfa5ace to your computer and use it in GitHub Desktop.

Select an option

Save ktilcu/87b18e3be9ad560151708f6efbfa5ace to your computer and use it in GitHub Desktop.
PG Pooling with express
const db = require('./db');
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
db.init()
// after init
.then(() => app.listen(3000, () => console.log('Example app listening on port 3000!')))
const {Pool} = require('pg');
let pool = undefined;
const init = () =>
creds
.getCreds('thunder_aurora')
.then(dbCreds =>
new Pool({
user: dbCreds.username,
host: dbCreds.host,
database: dbCreds.dbname,
password: dbCreds.password
})
)
.then(newPool => pool = newPool);
const query = (text, params) => pool.query(text, params);
module.exports = {
init,
query,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment