-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbConfig.mysql.js
52 lines (43 loc) · 1.48 KB
/
dbConfig.mysql.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
45
46
47
48
49
50
51
52
require("dotenv").config();
const mysql = require('mysql2');
// const pool = mysql.createConnection({
// host: `${process.env.MYhost}`,
// user: `${process.env.MYuser}`,
// password: `${process.env.MYpassword}`,
// database: `${process.env.MYdatabase}`
// });
// pool.connect (function (error) {
// if(error) throw error;
// console.log("CONNECTED");
// console.log(`pool: `, pool);
// console.log(`process.env.MYhost: `, process.env.MYhost);
// console.log(`process.env.MYuser: `, process.env.MYuser);
// console.log(`process.env.MYdatabase: `, process.env.MYdatabase);
// });
const pool = mysql.createPool({
host: `${process.env.MYhost}`,
user: `${process.env.MYuser}`,
password: `${process.env.MYpassword}`,
database: `${process.env.MYdatabase}`,
waitForConnections: true,
connectionLimit: 5,
queueLimit: 0
});
pool.getConnection(function(err, connection) {
if(err) throw err;
console.log(`POOL CONNECTION ESTABLISHED `);
console.log(`process.env.MYhost: `, process.env.MYhost);
console.log(`process.env.MYuser: `, process.env.MYuser);
console.log(`process.env.MYdatabase: `, process.env.MYdatabase);
})
// Attempt to catch disconnects
pool.on('connection', function (connection) {
console.log('DB Connection established');
connection.on('error', function (err) {
console.error(new Date(), 'MySQL error', err.code);
});
connection.on('close', function (err) {
console.error(new Date(), 'MySQL close', err);
});
});
module.exports = pool;