I'm new to node js. I want to ask how to get data out of ".then" after the query from database?
Refer to my code
When I do console.log(theResult)
; it is returning as undefined.
How can I solve it?
I'm new to node js. I want to ask how to get data out of ".then" after the query from database?
Refer to my code
When I do console.log(theResult)
; it is returning as undefined.
How can I solve it?
You can use the power of async/await in that case and return the value from the function and use it anywhere.
Here your code goes for query which you have to wrap in async function and return the value:
const getValue = async () => {
return query.yourQueryMethod(conditions)
.then(data => {
return data;
})
.catch(err => {
return err;
});
}
Here the code where you execute your main async function:
const executeQueryAndExtractData = async () => {
var myData = await getValue();
console.log ({ myData });
}
// Here you execute the async function
executeQueryAndExtractData();