title: node.js, callback on the end of an http-proxy request?
body: <p>I'm trying to learn node.js, and my context is the http-proxy module from nodejitsu.</p>
  
  <p>I'd like to get access to the end of the proxy event, so that I can log how long the target server took to respond. However, I can't out how to create the appropriate callback or event handler. I've looked at the source for http-proxy, and it doesn't seem to take the conventional callback method.</p>
  
  <p>Here's a sample, I'm sure its a simple fix to someone that breaths Node:</p>
  
  <pre><code>/* demonstrate a basic proxy server that can log the time 
  it takes to execute a given hit on the destination server
  */
  var http = require('http'),
      httpProxy = require('http-proxy');
  
  // Create the proxy server
  httpProxy.createServer(function (req, res, proxy) {
      var startTime = ( new Date()).getTime();
  
      // NEED HELP HERE. 
      // something like this should do it?
      proxy.addListener("end",function() {
          var endTime = (new Date()).getTime();
          console.log("request took " + (endTime - startTime) + "ms");
      });
  
      proxy.proxyRequest(req, res, {
          host: 'localhost',
          port: 9000
      });
  }).listen(8000);
  
  // the destination server
  http.createServer(function (req, res) {
      res.writeHead(200, { 'Content-Type': 'text/plain' });
      res.write('request successfully proxied: ' + req.url +'\n' + JSON.stringify(req.headers, true, 2));
      // make the hit slow by pausing the end()
      setTimeout(function() {
          res.end();
      },2000);
  }).listen(9000);
  </code></pre>