var mysql = require('mysql'); var app = null var pool = null const connectionLimit = 66 exports.init = function(express) { app = express app.get('LOG').log('Database | Server to connect to is ' + app.get('CONF').database.host + '') pool = mysql.createPool({ connectionLimit : connectionLimit, host : app.get('CONF').database.host, port : app.get('CONF').database.port, database : app.get('CONF').database.database, user : app.get('CONF').database.user, password : app.get('CONF').database.password, waitForConnections : true }); var connectionCountTemp = 0; setInterval(function() { const connectionCount = pool._freeConnections.length if(connectionCount != connectionCountTemp) { connectionCountTemp = connectionCount if(connectionCount > (connectionLimit / 2)) { app.get('LOG').error(`Database | Connection count: ${connectionCount}`) } else { app.get('LOG').debug(`Connection count: ${connectionCount}`) } } }, 1000) return this; }