Save result of promises inside an array with async/await
I'm writing a script that should count elements in a JSON file. I can't figure out how to save results of promises in an array.
This is the async function that counts the elements:
async function countVulnerabilities(dir, project, branch) {
await count[dir](new URL(path.join('/dropbox/sast/', project, branch, dir), process.env.REMOTE_DRIVE_PATH))
.then((result) => {
return result
})
}
The function that calls it is this:
export function getLogs(req, res, id, project, branch) {
let count = []
if (checkMappedDrive()) {
getDirs(project, branch)
.then((dirs) => {
dirs.forEach((dir) => {
countVulnerabilities(dir, project, branch)
.then((result) => {
count.push(result)
console.log(result)
})
})
})
res.send(count)
} else {
res.send('Impossible to enstablish a connection with the remote drive')
}
}
How can I push results in the count
array? At the moment, it's returning []
.
Many thanks
async function countVulnerabilities(dir, project, branch) {
return await count[dir](new URL(path.join('/dropbox/sast/', project, branch, dir), process.env.REMOTE_DRIVE_PATH))
}
what is count in this function?