I want to make my socket.io connection modular, to make it run once even if I need it anytime and everywhere. How to I export it?
var server = require("http").Server(express);
var io = require("socket.io")(server);
server.listen(5000);
io.on('connection', function(client) {
client.on('order_'+userId, function(data) {
io.emit('order_'+userId,data); // emit to cilent of dashboard
});
});
How does required work? I'm seeing different pattern like
var moment = require('moment');
or sometime
var LocalStorage = require('node-localstorage').LocalStorage;
In my case I need not to assign it to any variable, and want it to execute on the fly. Possible?