title: Serving the socket.io javascript file to a client via node.js/express
body: <p>I'm trying to get a sample client connection working with socket.io and express (specifically, this one: <a href="http://www.catonmat.net/blog/nodejs-modules-socketio/" rel="nofollow">http://www.catonmat.net/blog/nodejs-modules-socketio/</a> with some pieces from the other examples at <a href="https://github.com/LearnBoost/socket.io/blob/master/examples/chat/app.js" rel="nofollow">https://github.com/LearnBoost/socket.io/blob/master/examples/chat/app.js</a>). </p>
  
  <p>I've gotten most of the pieces set up and working - the server runs, and I can hit / to get the index.jade file to the browser. However, once that happens, it does nothing. </p>
  
  <p>Server:</p>
  
  <pre><code>var io = require('socket.io');
  var express = require('express')
  , stylus = require('stylus')
  , nib = require('nib');
  
  var app = express.createServer()
  var io = io.listen(app);
  
  app.configure(function () {
    app.use(stylus.middleware({ src: __dirname + '/public', compile: compile }));
    app.use(express.static(__dirname + '/public'));
    app.set('views', __dirname);
    app.set('view engine', 'jade');
  
    function compile (str, path) {
      return stylus(str)
        .set('filename', path)
        .use(nib());
    };
  });
  
  app.get('/', function (req, res) {
    res.render('index', { layout: false });
  });
  
  
  app.listen(8080);
  
  io.sockets.on('connection', function (socket) {
    console.log('A socket connected!');
    socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
      console.log(data);
    });
    socket.on('disconnect', function () {
      console.log('user disconnected');
    });
  });
  </code></pre>
  
  <p>index.jade:</p>
  
  <pre><code>doctype 5
  html
    head
      link(href='/stylesheets/style.css', rel='stylesheet')
      script(src='http://code.jquery.com/jquery-1.6.1.min.js')
      script(src='/socket.io/socket.io.js')
      script
        // socket.io specific code
        var socket = io.connect('http://localhost:8080');
        socket.on('connect', function () {
          alert('connected');
        });
        socket.on('news', function (data) {
            console.log(data);
            socket.emit('my other event', { my: 'data' });
          });
    body
      #chat
  </code></pre>
  
  <p>It appears that the server isn't serving /socket.io/socket.io.js (http://localhost:8080/socket.io/socket.io.js yields an error). What do I need to do to get express to serve that file? I can't find that in any of the examples.</p>
  
  <p>Is there anything else I'm doing wrong here?</p>