Last active
June 5, 2016 07:57
-
-
Save hakatashi/6fe2d1f53d9235d0f8e6bf8ca65f4bfb to your computer and use it in GitHub Desktop.
How the Node.js module system works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const foo1 = require('./load.js'); | |
| const foo2 = require('./reload.js'); | |
| console.log(foo1 === foo2); // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo { | |
| constructor() { | |
| console.log('Foo has been loaded.'); | |
| this.bar = 42; | |
| } | |
| } | |
| module.exports = new Foo(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const foo = require('./foo.js'); | |
| foo.bar = 10; | |
| module.exports = foo; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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