Here is how you can implement socket.io with express.
var express = require('express')
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
//serve static files and index.html
app.use(express.static(__dirname + '/'));
app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); });
io.on('connection', function(socket){
//logic handled in here
});
http.listen(7000,function(){ console.log('listening on port: 7000'); });
The above code has one route for handling the serving of index.html, but of course you can extend with additional routes the same way you would in any other app.
Here is how you can have access to socket.io within a route in express generator.
In www:
var server = http.createServer(app);
var io = require('socket.io')(server);
module.exports = {io:io}
Within index.js
router.get('/', function(req, res, next) {
var io = require('../bin/www')
console.log('I now have access to io', io)
res.render('index', { title: 'Express' });
});
Note, the above example is purely showing you how to gain access to the io object within index.js. There are many better ways to require socket.io and pass the io object around, but those decisions seem to be outside the scope of this question.