I'm working on a node module and it runs two servers, a http one and a socket.io one.
My http server is located in lib/http
and my socket.io one is located in lib/ws
.
I have a file called bin/dsmnet
.
In that file I invoke my http and socket.io server but I have a variable called users
and I need both servers to be able to modify the variable and to share it.
Here is my current code:
var dhttp = require('../lib/http');
var ws = require('../lib/ws');
var start = function (users, key, loglevel){
//Starts WebSocket and HTTP Server
dhttp.listen(users, 3265);
ws.listen(RSAkey, users, 3266);
}
Now I need to share the users variable between the two functions which are both located in two separate files.
Should I merge the http and socket.io server into one function and file so they can both use the same variable or is there another solution.
EDIT: To clarify I want to be able to append an array to my variable in my ws function in ws.js and read the array in my dhttp function in http.js and vice versa.