title: Node.js: TypeError: Object socket.io has no method 'listen'
body: <p>I'm making a little Node app using <code>socket.io</code> 0.9.13 using Express 3.0.6. I can't seem to anything even starting to run because it says <code>socket.io</code> has no method <code>listen()</code>. Here's my code (compiled coffeescript, so it's a bit ugly):</p>
  
  <pre><code>(function() {
    var app, express, io, port, usernames;
  
    express = require('express');
  
    app = express();
  
    io = require('socket.io'.listen(3000));
  
    port = 3000;
  
    app.listen(port);
  
    console.log("Listening on port " + port);
  
    console.log('CNTRL-C to quit.');
  
    app.engine('hamlc', require('haml-coffee'.__express));
  
    app.get('/', function(request, response) {
      return response.render('index.hamlc');
    });
  
    usernames = {};
  
    io.sockets.on('connection', function(socket) {
      socket.on('send-chat', function(msg) {
        return io.sockets.emit('update-chat', socket.username, msg);
      });
      socket.on('add-user', function(username) {
        socket.username = username;
        usernames[username] = username;
        socket.emit('update-chat', 'SERVER', "You have connected as " + username + ".");
        socket.broadcast.emit('update-users', 'SERVER', "" + username + " has joined the chat.");
        return io.sockets.emit('update-users', usernames);
      });
      return socket.on('disconnect', function() {
        delete usernames[socket.username];
        io.sockets.emit('update-users', usernames);
        return socket.broadcast.emit('update-chat', 'SERVER', "" + socket.username + " has disconnected from chat");
      });
    });
  
  }).call(this);
  </code></pre>
  
  <p>Which raises the following error:</p>
  
  <pre><code>node.js:201
          throw e; // process.nextTick error, or 'error' event on first tick
                ^
  TypeError: Object socket.io has no method 'listen'
      at Object.&lt;anonymous&gt; (/Users/chris/src/web/kouv/app.js:8:28)
      at Object.&lt;anonymous&gt; (/Users/chris/src/web/kouv/app.js:44:4)
      at Module._compile (module.js:432:26)
      at Object..js (module.js:450:10)
      at Module.load (module.js:351:31)
      at Function._load (module.js:310:12)
      at Array.0 (module.js:470:10)
      at EventEmitter._tickCallback (node.js:192:40)
  </code></pre>
  
  <p>Answer appreciated greatly. :-)</p>