title: Nodejs web server calling requestListener twice when page is loaded
body: <p>The following is the example web server from the documentation, with an added counter.  It prints the counter to the console whenever a client/browser requests the page.</p>
  
  <p>However, it's being called twice when requested by the browser.  Why?</p>
  
  <p>This is what I would expect would happen:</p>
  
  <pre><code>browser : Hello World 1
  console : Counter 1
  [reload page]
  browser : Hello World 2
  console : Counter 2
  </code></pre>
  
  <p>but this happens:</p>
  
  <pre><code>browser : Hello World 1
  console : Counter 1
            Counter 2
  [reload page]
  browser : Hello World 3
  console : Counter 3
            Counter 4
  </code></pre>
  
  <p>I run the code using the command line</p>
  
  <pre><code>$ node example.js
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>  var 
      http = require('http'),
      counter = 0,
      sys = require('util');
    http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      counter++;
      res.end('Hello World ' + counter + '\n');
      sys.puts('Counter ' + counter);
    }).listen(8000, "");
  </code></pre>