Hi
I am trying to use the async code as shown in the Node.js course.
I am exporting the async function (below).
The function is querying form a postgres SQL.
When I console log the result inside the function, I get correct data.
When I query the return of the result I get undefined.
I need to use the return data in the rest of the program
It looks like I get the print of the return before the function ends.
How can I use the return data in the rest of the program?
The function
exports.getData = async function(client,table){
await client.query(`SELECT * FROM ${table} `
, (err, result)=>{
if (err) throw err;
console.log(result.rows); // Here I see the result
return result.rows;
});
};
// **The call to the function**
console.log(await cs.getData(client, user)); //Here I get undefine