I have the following code for my post request in Express:
app.post('/', urlencodedParser, (req, res) => {
let value = req.body.value;
let result = data.map(async (currentObject) => {
return {
nodeName: currentObject.nodeName,
nodeStatus: await lib.checkValue(currentObject.nodeUrl,
currentObject.nodeName, value)
};
});
console.log(Promise.all(result));
res.render('list', {data:data, value:value});
})
I pass the function to map asynchronously. Then I use Promise.all
to get the result when all the promises return.
However, Promise.all
itself returns a promise Promise { [ Promise { <pending> }, Promise { <pending> } ] }
Without async, it returns the object [ { nodeName: currentObject.nodeName, nodeStatus: Promise { <pending> }} ]
. I'd like to await when my function returns and get the nodeStatus
.
Why is this happening? Am I missing something?