So, I'm trying to make the getConnection and querying asynchronously in my node.js project as I want to render my response only after my query. This is the code,
router.post('/', function(req, res, next) {
var queryRows;
con.getConnection(function(error, connection) {
if(error) {
} else {
connection.query('SELECT * FROM Tablee', function(error, rows, fields){
queryRows = rows;
});
}
});
res.render('home', {data:queryRows});
}
I want to run the getConnection()
and code inside first; and then render.
I followed the exact solution given in this Question, But in vain. the connection itself is undefined; so query returns error.
I'm using Node version 8 to support async and await; But I'm not able to get the result.