Exports is a helper that actually points to Module.exports. Exports is the recommended way to go, unless you need to chance the Object type of Module.exports. So generally:
Bad: Module.exports = {} Good: Exports.name = function(){}
// In the real world, this would be saved as it's own file. | |
exports.name = function() { | |
console.log('Hi!') | |
} | |
// In a separate file, you would call the above. | |
var thing = require('./thing'); | |
thing.name(); // Hi! |
module.exports = 'Derp' | |
exports.name = function() { | |
console.log('Hi!'); | |
} | |
// Calling the above... | |
var thing = require('./thing'); | |
thing.name(); // TypeError: Object 'Derp' has no method '.name' | |