-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.js
44 lines (37 loc) · 957 Bytes
/
connection.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
37
38
39
40
41
42
43
44
// import module
const mysql = require("mysql");
const dotenv = require("dotenv");
require("dotenv").config();
// init connection
const result = dotenv.config();
if (result.error) {
throw result.error;
}
const connection = mysql.createPool({
host: process.env.DOKKU_HOST,
user: process.env.DOKKU_USER,
password: process.env.DOKKU_PASSWORD,
database: process.env.DOKKU_DATABASE,
});
// check connection
connection.getConnection((err, connect) => {
if (err) {
console.error("error connecting:" + err.stack);
return;
}
connect.release();
console.log("connected as id" + connect.threadId);
});
// check errors
connection.on("error", (err) => {
if (err) throw new err();
});
// pool event
connection.on("release", (connect) => {
console.log("connection %d released", connect.threadId);
});
/* connection.end((err) => {
if (err) throw new err();
}); */
// export
module.exports = connection;