-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
36 lines (30 loc) · 954 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
36
"use strict";
/** Database setup for festy. */
const { Client } = require("pg");
require('dotenv').config();
const fs = require('fs');
const sslConfig = {
rejectUnauthorized: true, // This should be true to verify the server's certificate against the CA
ca: fs.readFileSync('./us-west-1-bundle.pem').toString(), // Adjust the path as necessary
};
// Create a new client instance without specifying connection details.
// The pg library will automatically use environment variables
// such as PGUSER, PGPASSWORD, PGHOST, PGPORT, and PGDATABASE.
const db = new Client(
{
host: process.env.PGHOST,
user: process.env.PGUSER,
password: process.env.PGPASSWORD,
port: process.env.PGPORT,
database: process.env.PGDATABASE,
ssl: sslConfig,
}
);
db.connect((err) => {
if (err) {
console.error('Database connection failed: ' + err.stack);
return;
}
console.log('Connected to database.');
});
module.exports = db;