I want multiple functions that have callbacks and this functions will return data of DB. An example:
getStates: function (callback) {
try {
dbExecution.executeQuery("SELECT * FROM Table",
function (err) {
console.log(err);
}, function (rowCount, more, rows) {
if (rowCount > 0) {
callback(rows);
} else {
callback(null);
}
});
} catch (ex) {
console.log(ex);
callback(null);
}
}
But this function is only one, I have a five functions that do same but get diferent data. The "main" function:
router.get('/content', sessionChecker, function (req, res) {
Module.getStates(function (data) {
res.render('info-user', { states: data });
});
Module.getReligion(function (data) {
res.render('info-user', { religions: data });
});
});
How can I do to call the 5 functions with Asynchronous Javascript (States, City, Religion, etc.) without having nested the functions?