I have a forEach
that goes through a list of codes and inside it I have a select that queries the records of the database. After forEach
, the data is sent from my server to my client, but forEach
does not wait for the result SELECT
to reach to execute the next element.
How can I do to forEach
expect the result
lista.forEach(function (row) {
db.query("select * from cad_prospectos where = ?", [row.codigo], function(err, pesquisa){
result.push(pesquisa)
})
})
cb(result)
my return function cb
returns empty