Skip to content

Instantly share code, notes, and snippets.

@nickylimjj
Last active July 22, 2016 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickylimjj/ccbc246a57f39ae62e8d7c198748a245 to your computer and use it in GitHub Desktop.
Save nickylimjj/ccbc246a57f39ae62e8d7c198748a245 to your computer and use it in GitHub Desktop.
Nodejs: module.exports vs exports
// module.exports
module.exports = function greet () {
console.log('greet1 [module.exports]')
}
console.log(exports)
console.log(module.exports)
// exports
exports.greet = function greet () {
console.log('greet2 [exports]')
}
console.log(exports)
console.log(module.exports)
// 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