title: In a node js http server how to know when an http exchange ended?
body: <p>I'm writing an http server application in node js. I want to have an event that triggers when an http exchange is over but I couldn't figure out how to do it. I tried to do it the way it would be done with other streams in node js using <code>.on('end', callback)</code> but it doesn't seem to work:</p>
  <p>what I tried (which doesn't work):</p>
  <pre class="lang-js prettyprint-override"><code>const Http = require('http');
  
  const httpServer = Http.createServer((httpRequest, httpResponse) =&gt; {
      console.log('&lt;started&gt;');
      httpResponse.on('end', () =&gt; console.log('&lt;ended&gt;'));
      httpResponse.end('END');
      console.log('&lt;finished&gt;');
  });
  httpServer.listen(80);
  </code></pre>
  <p>what I expect my console to print after navigating to <code>localhost</code> in my browser:</p>
  <pre><code>&lt;started&gt;
  &lt;finished&gt;
  &lt;ended&gt;
  </code></pre>
  <p>what I really get:</p>
  <pre><code>&lt;started&gt;
  &lt;finished&gt;
  </code></pre>
  <p>How to do this correctly? I want a callback that triggers when the server finished streaming the response stream for this http request to the client.</p>