-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
35 lines (30 loc) · 1022 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const Pool = require("pg").Pool;
require("dotenv").config();
// const devConfig = {
// user: process.env.PGUSER,
// host: process.env.PGHOST,
// database: process.env.PGDATABASE,
// password: process.env.PGPASSWORD,
// port: process.env.PGPORT,
// max: 20,
// connectionTimeoutMillis: 0,
// idleTimeoutMillis: 0,
// ssl: {
// rejectUnauthorized: false,
// }
// };
const devConfig = `postgresql://${process.env.PGUSER}:${process.env.PGPASSWORD}@${process.env.PGHOST}:${process.env.PGPORT}/${process.env.PGDATABASE}`;
const proConfig = process.env.DATABASE_URL; //heroku addons
const pool = new Pool({
connectionString: process.env.NODE_ENV === "production" ? proConfig : devConfig,
ssl: {
rejectUnauthorized: false
}
});
// the pool will emit an error on behalf of any idle clients
// it contains if a backend error or network partition happens
pool.on("error", (err, client) => {
console.error("Unexpected error on idle client", err);
process.exit(-1);
});
module.exports = pool;