title: host multiple pages on nodejs
body: <p>So I have my app at <code>http://localhost:8080/</code></p>
  
  <p>How can I have <code>http://localhost:8080/subpage</code> ? Because it seems like any page that hits :8080 pulls the server.js</p>
  
  <p>thanks!</p>
  
  <p>** edit - here's what worked for me (thanks to <strong>stewe's</strong> <em>answer</em>) **</p>
  
  <pre><code>var app = require('http').createServer(createServer);
  var fs = require('fs'); 
  var url = require('url');
  
  function createServer(req, res) {
      var path = url.parse(req.url).pathname;
      var fsCallback = function(error, data) {
          if(error) throw error;
  
          res.writeHead(200);
          res.write(data);
          res.end();
      }
  
      switch(path) {
          case '/subpage':
              doc = fs.readFile(__dirname + '/subpage.html', fsCallback);
          break;
          default:
              doc = fs.readFile(__dirname + '/index.html', fsCallback);
          break;
      }
  }
  
  app.listen(8080);
  </code></pre>