In my chat application using nodejs and socket.io, I need to share variable across different modules such that the value modified on one file should be accessed from other file. A workflow of my app is as follows.
In main app.js I have included a controller file for authenticating "users.js" In which I use a variable say for example var onlineusers ={}; On each login, the value is inserted into this variable. For handling socket chat, I used another controller file named chat.js where I need to use the same variable onlineusers.
Now Consider 3 files app.js,user.js,chat.js
In app.js
var users = require('./users.js');
var chat = require('./chat.js');
users.set(app);
chat.set(app,io);
In user.js
module.exports.set = function(app) {
// var onlineusers modified in some function
}
In chat.js
module.exports.set = function(app,io) {
// var onlineusers modified in some function
}
What i need is sharing the variable var onlineusers value across different modules(user.js and chat.js)