title: Node.js - Serving an index.html file as well as serving web sockets
body: <p>I am new to Node and Socket.io and attempting to get the below code running. It is designed to service WebSocket requests, however I would like to amend it to also serve static content such as index.html.</p>
  
  <p>My web socket code is as follows:</p>
  
  <pre><code>var http        = require("http"),
      sys         = require("sys"),
      io          = require("socket.io"),
      GlobTrie    = require("glob-trie.js");
  
  var Brokaw = {};
  
  Brokaw.Server = function(port) {
  var self = this;
  
  // setup the basic HTTP server -- socket.io will wrap this
  var server  = http.createServer(function(req, res) {
      // We have to respond with something, otherwise the connections hang :(
      res.writeHead(404);
      res.close();
  });
  server.listen(port);
  
  this._io    = io.listen(server, { "resource": "brokaw" });
  this._trie  = new GlobTrie();
  
  this._io.on("connection", function(conn) {
      new Brokaw.Server.Client(conn, self);
  });
  };
  
      new Brokaw.Server(8080);
  </code></pre>
  
  <p>And my code to serve the index.html is as follows:</p>
  
  <pre><code>// Hardcode *all* HTTP requests to this server to serve up index.html
  fs.readFile(
      __dirname + '/index.html',
      function (err, data) {
          if (err) {
              res.writeHead(500);
              return res.end('Error loading index.html');
          }
  
          res.writeHead(200);
          res.end(data);
      }
  );
  </code></pre>
  
  <p>Can anyone advise on how to integrate the two i.e. amend the top code to serve my index.html file also?</p>
  
  <p>Appreciate any comments, and I have been struggling for many hours!</p>
  
  <p>Regards, Ben.</p>