I'm trying to send an object as a result, but the return line executes before the query is complete even though I'm using await. Using the debugger I saw that the res.status(200) executes before the query inside the service returns the result.
I tried putting it in a function and using then() but this also didn't work. I think I've used it wrong.
This is the controller.js I'm using await in.
let table = req.query.table;
let namespace = req.query.namespace;
table = table.toUpperCase();
namespace = namespace.toLowerCase();
try{
let serviceResponse = await testService.GetAny(table, namespace);
res.type('application/json').status(200).send(serviceResponse);
}
This is the service where the query is executed.
client.exec(getScript, (err, res) => {
if(err){
return console.error('Connect error ', err);
}
console.log('inside exec');
return res;
});