Created
November 6, 2017 14:11
-
-
Save maka-io/8d45d2db73b6054f689d306af6ac1144 to your computer and use it in GitHub Desktop.
Postgresql Database conenction
This file contains 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 pgLocalConfig = { | |
pgUser: '', | |
pgDatabase: '', | |
pgPassword: '', | |
pgHost: 'localhost', | |
pgPort: 5432, | |
pgMaxPoolClients: 10, | |
pgTimeoutMilli: 5000 | |
}; | |
export default pgLocalConfig; |
This file contains 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
import pg from 'pg'; | |
import colors from 'colors'; | |
import pgLocalConfig from './pg-config'; | |
const config = { | |
user: process.env.PGUSER || pgLocalConfig.pgUser, | |
database: process.env.PGDATABASE || pgLocalConfig.pgDatabase, | |
password: process.env.PGPASSWORD || pgLocalConfig.pgPassword, | |
host: process.env.PGHOST || pgLocalConfig.pgHost, | |
port: process.env.PGPORT || pgLocalConfig.pgPort, | |
max: process.env.PGMAXPOOLCLIENTS || pgLocalConfig.pgMaxPoolClients, | |
idleTimeoutMillis: process.env.PGTIMEOUTMILLI || pgLocalConfig.pgTimeoutMilli | |
}; | |
console.log(`[+] Enabling PG SQL client pool ...`.yellow); | |
const pgPool = new pg.Pool(config, err => { | |
console.log(`${err}`.red); | |
}); | |
export { pgPool }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment