Last active
May 10, 2018 16:35
-
-
Save ktilcu/87b18e3be9ad560151708f6efbfa5ace to your computer and use it in GitHub Desktop.
PG Pooling with express
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!'))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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