Created
August 4, 2014 02:15
-
-
Save kaelzhang/360efb9771234284bc78 to your computer and use it in GitHub Desktop.
Node.js File Module
This file contains 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
a.js | |
var b = require('./b') | |
b.b; // undefined | |
exports.a = 1; | |
b.js | |
var a = require('./a') -> a's module.exports | |
a.a; // 1 | |
exports.b = 2; | |
$ node b | |
require(id) -> search file by id | |
-> file not found -> error | |
-> file found -> | |
-> module.exports loaded -> return module.exports; | |
-> not -> empty module.exports -> pass module.exports into file -> set flag loaded=true, run file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment