title: mysql query inside loop node js
body: <p>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</p>
  
  <pre><code>   app.post('/consulta',(req,res)=&gt;{
      var data = req.body.frase;
      let consulta;
      let respuesta = [];
  
      for(let i=1;i&lt;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 &gt; 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);
              }
          });
      }
  
  })
  </code></pre>