title: cannot response.write on connection node.js
body: <p>I wrote this code in node.js :</p>
  
  <pre><code>var http = require('http');
  http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
      res.write('start\n');
      var mysql      = require('mysql');
      var connection = mysql.createConnection({
        host     : 'hostname',
        user     : 'user',
        password : 'pass',
        database : 'dbname',
      });
  
      connection.connect();
  
      connection.query('SELECT code FROM user_type', function(err, rows, fields) {
        if (err) throw err;
              //This for is to run on all the results
              for(var i=0;i&lt;2;i++){
              res.write('name:',rows[i].code);
          }
      });
  
      connection.end();
  
    res.end('End');
  }).listen(8080);
  console.log('Server running');
  </code></pre>
  
  <p>my questions are:
  1. why did the res.write in the for loop print nothing in my html page?
  2. what to write instead of 2 in the for?</p>