How to send one sql row per second through a socket io connection?
<p>I created a node.js server and am now trying to send my mysql data from a table to a browser (with a javascript client receiving the data).</p>

<p>My problem is that if I want to send all of the rows from my table, it works fine, but if I want to send just one row per second, it doesn't work.</p>

<p>This is what I am doing:
server side:</p>

<pre><code>io.on('connection', function (socket) {

  for (var i = 1; i &lt; 60; i++) {
    connection.query('SELECT * FROM jsonlines WHERE id="'+i+'"').on('result', function(data) {
      // Push results onto the notes array
      var a=  JSON.stringify(data);
      notes.push(a); //I want to save each line in an array notes

      setTimeout(function() {
        socket.emit('news', notes[i]);
        console.log(a);
      }, (1 * 1000));
    });
  }

 });
</code></pre>

<p>So basicaly I have an id in my table that is different for each row and, am selecting the rows in a for loop.
Settimeout serves to do a 1 second delay so that the socket.emit() only sends my data 1 second after the query has been done.</p>

<p>However, <code>console.log(a)</code> print all my rows imidiatelly, with the delay.</p>

<p>What am I doing wrong?
Thank you.</p>