Skip to content

Instantly share code, notes, and snippets.

@maka-io
Created November 6, 2017 14:11
Show Gist options
  • Save maka-io/8d45d2db73b6054f689d306af6ac1144 to your computer and use it in GitHub Desktop.
Save maka-io/8d45d2db73b6054f689d306af6ac1144 to your computer and use it in GitHub Desktop.
Postgresql Database conenction
const pgLocalConfig = {
pgUser: '',
pgDatabase: '',
pgPassword: '',
pgHost: 'localhost',
pgPort: 5432,
pgMaxPoolClients: 10,
pgTimeoutMilli: 5000
};
export default pgLocalConfig;
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