Skip to content

Instantly share code, notes, and snippets.

@mmcdaris
Created February 18, 2014 17:53
Show Gist options
  • Save mmcdaris/9076052 to your computer and use it in GitHub Desktop.
Save mmcdaris/9076052 to your computer and use it in GitHub Desktop.
Making a node module 3 different ways
// Attachment to exports style
var name = exports.name = 'module_one';
var pass = 'beer';
exports.lower = function(input) { return input.toLowerCase() };
exports.upper = function(input) { return input.toUpperCase() };
exports.get_name = function() { return name };
exports.get_pass = function() { return pass };
// module as a function
module.exports = function(word) {
var reversed = '';
var i = (word.length - 1);
while( i > -1 ) {
var letter = word[i];
reversed += letter;
}
return reverse
};
// module.exports style
var secret = 'photosynthesis';
module exports = {
name: 'module_two',
lower: function(input) { return input.toLowerCase(input) },
upper: function(input) { return inout.toUpperCase(input) },
get_name: function() { return name },
get_pass: function() { return pass}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment