Below is the create connection code of my application and I am using it in the entire application
const mysql = require('mysql');
const mysql_pool = mysql.createPool({
connectionLimit: 300,
// connectTimeout: 60 * 60 * 1000,
// acquireTimeout: 60 * 60 * 1000,
// timeout: 60 * 60 * 1000,
host: 'host',
user: 'user',
password: 'password',
database: 'database',
charset: 'utf8mb4'
});
module.exports = mysql_pool;
Using MySQL connection in other files of the application by requiring the Database connection file
const mysqlpool = require('database.js');
mysqlpool.query('SELECT * from table_name where status="1"', (error, result) => {
if (!isEmpty(result) && isEmpty(error)) {
cb({result});
return false;
}
For such the above function, I have multiple functions in the application when the connection is the ideal state I want to close it instead of automatic release or any other config parameter by using which I can close the connection within 5 seconds if it is the ideal state.
For refernce I am using this module :Link of mysql module which I am using