Created
January 27, 2014 19:54
-
-
Save rmg/8656027 to your computer and use it in GitHub Desktop.
Behaviour of Node's require() under repl, module, and -e.
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
$ cat req.js | |
console.log('global.require', global.require) | |
console.log('bare require', require) | |
console.log('global.require === require', global.require === require) | |
$ node req.js | |
global.require undefined | |
bare require function require(path) { | |
return self.require(path); | |
} | |
global.require === require false | |
$ node -e "$(cat req.js)" | |
global.require function require(path) { | |
return self.require(path); | |
} | |
bare require function require(path) { | |
return self.require(path); | |
} | |
global.require === require true | |
$ node < req.js | |
global.require function require(path) { | |
return self.require(path); | |
} | |
bare require function require(path) { | |
return self.require(path); | |
} | |
global.require === require true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The global object in V8 is of different opinion:
And here is the cause: lib/module.js#L407-L415