Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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?

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda