0

My gethealth() function contains chained promises. In version route, I want to return the object but I am currently getting pending promises in return. I am not sure how to resolve each Promise in my systemHealth object

export const version = (req, res) => {
  const systemHealth = gethealth()
  res.status(200).send(systemHealth)
}

result:

console.log(systemHealth)

[ Promise { <pending> },
  Promise { <pending> },
  Promise { <pending> },
  Promise { <pending> } ]
Liondancer
  • 15,721
  • 51
  • 149
  • 255
  • 1
    See the linked question's answers. You need to *consume* the promises. Since you're returning an array of them, the best way is probably `Promise.all`, which waits for them all to fulfill: `export const version = (req, res) => { Promise.all(gethealth()) .then(systemHealth => { res.status(200).send(systemHealth); }); }` (More readable: https://pastebin.com/W3t7vWvn) – T.J. Crowder Mar 17 '20 at 11:03
  • 1
    @T.J.Crowder PERFECT this is just what I needed! If you answer the question. I will accept! – Liondancer Mar 17 '20 at 11:05

0 Answers0