0

Title may seem a little misleading so let me elaborate on this. I need to set the value of a variable (within current context) and share it among other apps which needs to use this variable.

Let's say there is a counter module counter.js:

var Counter = module.exports = {
    count: 0,
    add: function() {
        Counter.count += 1;
    }
}

I use it in my counter-app.js like this:

var counter = require("./counter");
setInterval(function() {
    counter.add();
    console.log(counter.count);
}, 1000);

It starts to set and display numbers sequentially which is good so far.

While above app is running, I make another app named counter-var.js which contains:

var counter = require("./counter");
console.log(counter.count);

I need counter-var.js to print out current Counter.count variable value which is set by first app. Is there any way to achieve this sharing without using databases (redis, e.g.)?

revo
  • 47,783
  • 14
  • 74
  • 117

0 Answers0