I am building a simple web app with node.js, express 4 and socket.io (latest version).
My problem is that the proposed syntax for socket.io (from their website) does not correspond with what I have from express.
This is the socket.io way to include everything and get started:
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
Problem though is that I have auto generated a project with express-generator and the beginning of my code looks like this:
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();
Also, this is my 'bin/www' file:
#!/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);
});
I do not seem to find any reference to the 'http' package and running socket.io seems to depend on it.
What is the proper way to include and work with socket.io in an express 4 project?
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?
Any ideas?