This is code in my node.js project but I can't access the value of connection2
. I read somewhere that .getConnection is asynchronous function so I can't get the value of connection2 this way. How can I modify this code to properly return the value?
var mysql = require('mysql');
var connectionPool = mysql.createPool({
host: 'localhost',
user: 'root',
password: '',
database: 'rockcity_followme'
});
exports.connExport=function() {
var connection2;
connectionPool.getConnection(function (err, connection) {
connection2=connection;
});
return connection2;
}