So here is the deal: I'm trying to use socket.io in an express project. After Express Js 4 was lauched, i've updated my express-generator and now the app initial functions goes into ./bin/www
file, including those vars (www file contents: http://jsfiddle.net/avMa5/ )
var server = app.listen(app.get('port'), function() {..}
(check it by npm install -g express-generator
and then express myApp
that being said, let's remember how socket.io docs ask us to fire it:
var app = require('express').createServer();
var io = require('socket.io')(app);
Ok but i can't do it inside app.js, like recommended. This should be done in ./bin/www in order to work. in ./bin/www this is what i can do to get it working:
var io = require('socket.io')(server)
Ok this works, but i can't use the io var anywhere else, and i really don't want to put my socket.io functions on www
file.
I guess this is just basic syntax, but I can't get this to work, not even using module.exports = server
or server.exports = server
nor module.exports.io = app(io)
on www file
So the question is: how can i use socket.io having this /bin/www file as starting point of my app?