title: Node.js MYSQL to run each Queries sequencially after previous one is done?
body: <p>I'm using Javascript MYSQL Library from Node.js and then i have multiple queries to run in loop. But when i run the loop, <code>the loop</code> always reach to end (done) suddenly while the Queries it started are still processing. So how do i keep the loop to wait each Query til done and then continue normally?</p>
  
  <p>My code is:</p>
  
  <pre><code>function startHere() {
      console.log("-- START --");
      for (i=1; i &lt; 6; i++) {
          dbInsert(i);
      }
      console.log("-- END --");
  }
  function dbInsert(id) {
      connection.query (
          'INSERT INTO table SET data=?',
          [id],
          function selectCb(err, results, fields) {
              if (err) {
                  console.log(err.message);
              }
              if (results.length &gt; 0) {
                  console.log(id+" RECORDS ADDED!");
              }
          }
      );
  }
  startHere();
  </code></pre>
  
  <p>When i run it, it always returns like:</p>
  
  <pre><code>-- START --
  -- END --
  1 RECORDS ADDED!
  2 RECORDS ADDED!
  3 RECORDS ADDED!
  4 RECORDS ADDED!
  5 RECORDS ADDED!
  </code></pre>
  
  <p>It means, the loop doesn't wait the end of the queries it started.<br>
  How can i detect the end-point of the queries and make it work?</p>