exports.* functions: getting other variables

I have the following code:

//app.js
var ioroutes = require('./controllers/socket');
sIo.sockets.on('connection', ioroutes.connection);

//socket.js
exports.connection = function(socket){
  console.log('I have ' + socket);
};

Now, from app.js I can access the sIo object, which I want to use to see how many clients I have connected. How can I pass the sIo object to the exported 'connection' function?

Thanks in advance.

You would need to add it as a parameter to the connection function:

//app.js
var ioroutes = require('./controllers/socket');
sIo.sockets.on('connection', function(socket) {
  ioroutes.connection(socket, sIo);
});

//socket.js
exports.connection = function(socket, sIo){
  console.log('I have ' + socket);
};