Looking for a way to validate mysql connections.
What is the best approach to ensure the connection before proceeding in a function?
function _testConnection( _host, _user, _password, _database) {
let isConnected = false;
let connection = mysql.createConnection({
host : _host,
user : _user,
password : _password,
database : _database
});
connection.connect((err) => {
isConnected = !err;
connection.destroy();
});
// Is there a method to delay execution until the connection is established?
return isConnected;
}