I will try be simple, when I want to execute a query async in a function (SetLogs), I will see in my logs my console.log('query 1 log')
at the end of all my call, instead to see him between console.log('start log ');
and console.log('return pool logs');
I have 2 parts :
My main call
logs.SetLogs(pool, req, res).then(bResultLog=> {
console.log('return pool logs');
})
console.log("END")
return pool
SetLogs Function :
static async SetLogs(pool, req, res) {
var now = new Date();
var endpoint = req.originalUrl.split("?")[0].replace("/", "")
var query = "INSERT INTO LOGS_PORTAIL (ENDPOINT, TYPE, DATE_HEURE_LOGS, LOGIN) VALUE ('" + endpoint + "','" + req.method + "','" + now.toISOString().slice(0, 19).replace('T', ' ') + "','" + 'API' + "')";
console.log('start log ');
pool.query(query, function(err, results) {
console.log('query 1 log ');
return true
});
console.log('fin log ');
}
This is my logs :
start log
fin log
END
return pool logs
query 1 log