node.js - shared client beetwen different modules with socket.io?

I've got something like this:

io.sockets.on('connection', function(player) {
    var currentRoom;
    currentRoom='lobby';
    player.join(currentRoom);
    player.broadcast.to(currentRoom).emit('newPlayer');

    require('./test').test(player);

    player.on('changeroom',function(room) {
        player.leave(currentRoom);
        player.join(room);
        currentRoom = room;
    });

});

test.js:

exports.test = function(player) {
    player.on('message',function(msg) {
            player.broadcast.to('lobby').emit('message',msg);
    });
}

I want to change 'lobby' to currentRoom value in test.js. How can I do this?

You could pass it as an argument:

exports.test = function(player, currentRoom) {
        player.on('message',function(msg) {
                player.broadcast.to(currentRoom).emit('message',msg);
        });
    }

It works due to javascript Closures

Or you could put it in exports.currentRoom