forked from mukeshsharma1426/hapiv17-mysql-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.js
30 lines (24 loc) · 792 Bytes
/
bootstrap.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
const MYSQL = require('mysql');
// load env variables
const dotenv = require('dotenv');
dotenv.config();
var db_config = {
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASS,
database: process.env.MYSQL_DBNAME,
port: process.env.MYSQL_PORT,
multipleStatements: true
};
function initializeConnectionPool(db_config){
var numConnectionsInPool = 0;
console.log('CALLING MYSQL INITIALIZE POOL:');
console.log(db_config);
var conn = MYSQL.createPool(db_config);
conn.on('connection', function (connection) {
numConnectionsInPool++;
console.log('NUMBER OF CONNECTION IN POOL : ', numConnectionsInPool);
});
return conn;
}
global.connection = initializeConnectionPool(db_config);