title: How to pass HTTP response to a callback in Node.js?
body: <p>When querying a database from Node, how does one pass the HTTP response object to the aysynchronous callback?  For example (db stuff is pseudocode):</p>
  
  <pre class="lang-js prettyprint-override"><code>var http = require('http');
  http.createServer(function (request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    // read from database:
    var dbClient = createClient(myCredentials);
    var myQuery = 'my query goes here';
    dbClient.query(myQuery, callback);
  
    function callback(error, results, response) // Pass 'response' to the callback?
    {
      if (error === null) {
        for (var index in results) response.write(index); // Error
        response.end('End of data');
      }
      else {
        response.end('Error querying database.')
      }
    }
  }).listen(1337, "127.0.0.1");
  </code></pre>
  
  <p>When passing <code>response</code> to the callback, Node gives an error that the results continuation object has no method <code>write</code>.</p>
  
  <p>What's the best strategy here?</p>