-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
28 lines (24 loc) · 747 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
const { Pool } = require('pg');
require('dotenv').config();
const poolConfig = {
max: 5,
min: 2,
idleTimeoutMillis: 600000,
};
const pool = process.env.External_DB_URL_Render ?
new Pool({
connectionString: process.env.External_DB_URL_Render,
ssl: {
rejectUnauthorized: false
}
}) :
(() => {
const user = process.env.DB_USER;
const password = process.env.DB_PASSWORD;
const host = process.env.DB_HOST;
const port = process.env.DB_PORT;
const database = process.env.DB_NAME;
poolConfig.connectionString = `postgres://${user}:${password}@${host}:${port}/${database}`;
return new Pool(poolConfig);
})();
module.exports = pool;