title: httpServer in node.js to serve three.js
body: <p><a href="https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally" rel="nofollow">https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally</a> suggests that three.js examples be served by a local server. The python SimpleHTTPServer works fine for me, except that I need to run it in the directory above the <strong>examples</strong> dir in the three.js repository clone.</p>
  
  <p>Now I'm trying to serve up the same example using httpServer in node.js. I could use one of the node versions of SimpleHTTPServer, but I need a httpServer object to pass data from the server to the webgl browser example via socket.io. So I took the socket.io example and tried the following <strong>server.js</strong> to be run using node in the directory above <strong>examples</strong>. </p>
  
  <pre><code>var app = require('http').createServer(handler)
    , io = require('socket.io').listen(app)
    , fs = require('fs')
  
  app.listen(8080);
  
  function handler (req, res) {
    fs.readFile(__dirname + '/examples/webgl_interactive_voxelpainter.html',
    function (err, data) {
      if (err) {
        res.writeHead(500);
        return res.end('Error loading html');
      }
  
      res.writeHead(200);
      res.end(data);
    });
  }
  
  io.sockets.on('connection', function (socket) {
    socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
      console.log(data);
    });
  });
  </code></pre>
  
  <p>Net is that on 127.0.0.1:8080 with node I can't see the three.js example. The code doesn't work even if I remove all references to socket.io, indicating it's something about html. </p>
  
  <ol>
  <li><p>What am I missing? The html file is being read properly because I don't get a callback error. </p></li>
  <li><p>I noticed that the python server lists the directory as html links in the browser. I click <strong>examples</strong> to see the html files, then click the html file and it works fine. So I tried running the 'node server.js' one directory level up, with just about every combination of forward and backward slashes, root directory references,... to no avail. </p></li>
  <li><p>I'm not hung up on pure httpServer. If express or something else works with socket.io and three.js, I'll board that train.</p></li>
  </ol>