Module assignment of nodejs, global variable

how nodejs permanently changes the properties in the module is similar to reference passing.
A js file require is assigned to change the property, and other js require is directly followed by the new value.
what you really want is a global variable, but you can change it at any time, and other file references are changed values after the change

Jan.19,2022

New global.js


class Foo {
  constructor ({name, age} = {name: 'foo', age: 0}) {
    this.name = name
    this.age = age
  }
}

module.exports = new Foo()

if you change the value in any file, the values in name, and age, will change

.
Menu