forked from harshn08/fruit-app-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
34 lines (32 loc) · 917 Bytes
/
main.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
const { Pool } = require("pg");
const path = require("path");
const fs = require("fs");
require("dotenv").config();
var config = {
user: process.env.APPLICATION_DB_USER,
host: process.env.POSTGRES_HOST,
password: process.env.APPLICATION_DB_INITIAL_PASSWORD,
database: process.env.POSTGRES_DB,
port: 5432,
ssl: {
rejectUnauthorized: false,
key: fs.readFileSync(path.resolve(__dirname, "pg_server.key")).toString(),
cert: fs.readFileSync(path.resolve(__dirname, "pg_server.crt")).toString(),
},
};
const pool = new Pool(config);
pool
.connect()
.then((client) => {
console.log("connected");
// promise
client
.query("SELECT * FROM names")
.then((res) => {
console.log(res.rows);
client.release();
})
.catch((e) => console.error(e.stack));
})
.catch((err) => console.error("error connecting", err.stack))
.then(() => pool.end());