title: Handling multiple parallel HTTP requests in Node.js
body: <p>I know that Node is non-blocking, but I just realized that the default behaviour of <code>http.listen(8000)</code> means that all HTTP requests are handled one-at-a-time. I know I shouldn't have been surprised at this (it's how ports work), but it does make me seriously wonder how to write my code so that I can handle multiple, parallel HTTP requests. </p>
  
  <p>So what's the best way to write a server so that it doesn't hog port 80 and long-running responses don't result in long request queues?</p>
  
  <p>To illustrate the problem, try running the code below and loading it up in two browser tabs at the same time.</p>
  
  <pre><code>var http = require('http');
  http.createServer(function (req, res) {
      res.setHeader('Content-Type', 'text/html; charset=utf-8');
      res.write("&lt;p&gt;" + new Date().toString() + ": starting response");
      setTimeout(function () {
          res.write("&lt;p&gt;" + new Date().toString() + ": completing response and closing connection&lt;/p&gt;");
          res.end();
      }, 4000);
  }).listen(8080);
  </code></pre>