title: Socket.io and Express 4
body: <p>I am building a simple web app with node.js, express 4 and socket.io (latest version). </p>
  
  <p>My problem is that the proposed syntax for socket.io (from their website) does not correspond with what I have from express.</p>
  
  <p>This is the socket.io way to include everything and get started:</p>
  
  <pre><code>var app = require('express')();
  var server = require('http').Server(app);
  var io = require('socket.io')(server);
  </code></pre>
  
  <p>Problem though is that I have auto generated a project with express-generator and the beginning of my code looks like this:</p>
  
  <pre><code>var express = require('express'),
          path = require('path'),
          favicon = require('serve-favicon'),
          logger = require('morgan'),
          cookieParser = require('cookie-parser'),
          bodyParser = require('body-parser'),
          request = require('request');
  
  var routes = require('./routes/index'),
          users = require('./routes/users');
  
  var app = express();
  </code></pre>
  
  <p>Also, this is my 'bin/www' file:</p>
  
  <pre><code>#!/usr/bin/env node
  var debug = require('debug')('ase');
  var app = require('../app');
  
  app.set('port', process.env.PORT || 3000);
  
  var server = app.listen(app.get('port'), function() {
    debug('Express server listening on port ' + server.address().port);
  });
  </code></pre>
  
  <p>I do not seem to find any reference to the 'http' package and running socket.io seems to depend on it.</p>
  
  <p>What is the proper way to include and work with socket.io in an express 4 project?</p>
  
  <p>As a side question, how should I structure my code? That is, should I include all my socket.io logic inside the app.js (I think not) or should I make another file and link it?</p>
  
  <p>Any ideas?</p>