The problem is that the query is async inside loop, i need to execute something when the for and all the queries finished, if i execute something after the for the queries wasn't executed yet
app.post('/consulta',(req,res)=>{
var data = req.body.frase;
let consulta;
let respuesta = [];
for(let i=1;i<data.length;i++){
consulta = `SELECT * FROM imagen WHERE nombre = "${data[i-1] +' '+ data[i]}"`;
connection.query(consulta, function (error, results, fields) {
if (error) throw error;
if(results.length > 0){ // Si existe una seña que tenga 2 palabras
data[i-1] = data[i-1] +" "+data[i]; // Unidos jamas seran vencidos
data.splice(i, 1);
}
});
}
})
Promise.all().