title: Node.js / Express on response event
body: <p>I'm trying to create a middleware that logs response times and status codes and sends it to a database. However, I'm not sure what event to use. In node's documentation there's a <code>close</code> event but it is never fired. <code>end</code> doesn't work either. However, <code>header</code> does, but I can't find any documentation.</p>
  
  <pre><code>app.use(function(req, res, next) {
    res.on('close', function() {
      console.log('close')
    })
  
    res.on('end', function() {
      console.log('end')
    })
  
    res.on('header', function() {
      console.log('header')
      console.log(res.statusCode)
    })
  
    next()
  })
  </code></pre>
  
  <p>Only <code>header</code> fires, and it does return the correct res.statusCode.</p>
  
  <p>My questions:</p>
  
  <ol>
  <li>Why isn't <code>close</code> firing? Why is <code>header</code> firing?</li>
  <li>Is this a reliable way to go?</li>
  </ol>