title: How does the event: 'close' work in Node.js?
body: <p>I'm experimenting with the <code>close event</code> in Node.js. I'm very new to Node.js so I'm not sure if this is a decent question or a sad one.  </p>
  
  <p>Documentation for <code>close event</code>: 
  <a href="http://nodejs.org/api/http.html#http_event_close_2" rel="nofollow noreferrer">http://nodejs.org/api/http.html#http_event_close_2</a></p>
  
  <p>I want to output to the console a message if the browser is closed before the <code>end event</code> is reached. </p>
  
  <p>While the server ran and before it got to 15 seconds, I tried closing the browser and killing the process through Chrome Tools. No message is output to the console and if I open up other connections by visiting localhost:8080 with other windows, I quickly get a 'hello' indicating my node server thinks there are at least two connections.</p>
  
  <p>I'm either not understanding how to kill processes in Chrome  or how the event close works.</p>
  
  <p>Or if <code>End</code> and <code>Close</code> are the same - <a href="https://stackoverflow.com/questions/6537510/node-js-https-no-response-end-event-close-instead">node.js https no response &#39;end&#39; event, &#39;close&#39; instead?</a> - why isn't my "They got impatient!" message still ouput in the console?</p>
  
  <p>How can you output to a console if the process was ended before the event end was reached?</p>
  
  <pre><code>var http = require('http'),
      userRequests = 0;
  
  
  http.createServer(function(request,response){
  userRequests++;
  
  response.writeHead(200, {'Content-Type' : 'text/plain'});
  
  if ( userRequests == 1 ){
  
      response.write('1st \n');
      setTimeout ( function() {
          response.write('2nd Thanks for waiting. \n');
          response.on('close', function() {
  
              console.log("They got impatient!");
  
          });
          response.end();
      }, 15000);
      response.write('3rd \n');
  }
  else {
      // Quick response for all connections after first user
      response.write('Hello');
      response.end();
  }
  }).listen(8080, function() {
  console.log('Server start');
  });
  </code></pre>
  
  <p>Thank you.</p>