Skip to content

Instantly share code, notes, and snippets.

@edwardhotchkiss
Created May 25, 2012 03:09
Show Gist options
  • Save edwardhotchkiss/2785519 to your computer and use it in GitHub Desktop.
Save edwardhotchkiss/2785519 to your computer and use it in GitHub Desktop.
5 Ways to export the same Node.js module
var dude = require('./dude');
dude.say('hey bro.');
var dude = module.exports = function(){};
dude.say = function(message) {
console.log(message);
};
var dude = module.exports = {
say : function(message) {
console.log(message);
}
};
exports.say = function(message) {
console.log(message);
};
module.exports = Object.create({
say : function(message) {
console.log(message);
}
});
module.exports = function(params) {
return {
say : function(message) {
console.log(message);
}
}
}
var dude = new require('./dude')(/* params? */);
dude.say('hey bro.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment