I am trying to write a function inside a async function in nodejs. here is my sample script
module.exports = async function (context, req) {
var mydata = (async () => {
return "output needed"
}) ()
console.log(mydata)
}
Expected Output is : output needed
What I get is : promise{ <pending> }
Any Idea to wait till the promise is fulfilled?
You need to await the Promise
returned by mydata
:
async function test(context, req) {
var mydata = (async () => {
return "output needed"
}) ()
console.log(await mydata)
}
test()