I have two modules that need to access a shared array. I solve this by having a module that consists only of the following:
sharedArray.js
module.exports = [];
In modules, I use it as follows:
module1.js
var arr = require('./sharedArray');
function addSomething() {
}
module2.js
var arr = require('./sharedArray');
function doSomething() {
}
This works, but it seems wrong (useless empty module) and that I am missing something obvious.
Is there a better way to do this, or is it really how you solve it?
source
share