I want to make "variable sharing" in node.js but I cannot find a working way to do that.
My aim is to be able to change variables from an another file. For example, I have a
in my main file but after doing something in another file (test.js
), a
should change its value in the main file. Is it possible to accomplish and how?
I have tried this code but it does not seem to work.
main.js
let a = 10;
module.exports.test = a;
console.log(a);
require('./test.js');
console.log(a);
test.js
let b = require('./main.js').test;
b = 15;