Last active
July 22, 2016 06:10
-
-
Save nickylimjj/ccbc246a57f39ae62e8d7c198748a245 to your computer and use it in GitHub Desktop.
Nodejs: module.exports vs exports
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
// module.exports | |
module.exports = function greet () { | |
console.log('greet1 [module.exports]') | |
} | |
console.log(exports) | |
console.log(module.exports) |
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
// exports | |
exports.greet = function greet () { | |
console.log('greet2 [exports]') | |
} | |
console.log(exports) | |
console.log(module.exports) |
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
// module.exports (ME) vs exports (E) | |
var greetME = require('./greet1') | |
var greetE = require('./greet2') | |
// you can modify the `requre`'s return value | |
greet1() | |
// you ALWAYS get back an object, you can ONLY mutate it | |
greet2.greet() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment