Skip to content

Instantly share code, notes, and snippets.

@hakatashi
Last active June 5, 2016 07:57
Show Gist options
  • Select an option

  • Save hakatashi/6fe2d1f53d9235d0f8e6bf8ca65f4bfb to your computer and use it in GitHub Desktop.

Select an option

Save hakatashi/6fe2d1f53d9235d0f8e6bf8ca65f4bfb to your computer and use it in GitHub Desktop.
How the Node.js module system works
const foo1 = require('./load.js');
const foo2 = require('./reload.js');
console.log(foo1 === foo2); // true
class Foo {
constructor() {
console.log('Foo has been loaded.');
this.bar = 42;
}
}
module.exports = new Foo();
const foo = require('./foo.js');
foo.bar = 10;
module.exports = foo;
const foo = require('./foo.js');
console.log(foo.bar); // 10
module.exports = foo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment