How to modify module variables imported by node

in ES6 module, basic type variables are all reference relationships, so it is easy to modify the variable value

but it doesn"t work in Node module. What should I do?

var mod = require("./a.js")

mod.count();
mod.count();
mod.count();

console.log(mod.a);  // 10
a.js

var a = 10;
module.exports = {
  a,
  count() {aPP}
}

how to implement the relocation wizard in Node module?

ES6 module

export * from "./fileName.js"
May.05,2022

just the first question:

// a.js

let _a = 0;
module.exports = {
    get a() {
        return _a;
    },
    set a(v) {
        _a = v;
    },
    inc() {
        _aPP;
    }
};

the second question is very simple. Think for yourself.

Menu