Skip to content

Instantly share code, notes, and snippets.

@markdaws
Created February 7, 2012 09:07
Show Gist options
  • Save markdaws/1758429 to your computer and use it in GitHub Desktop.
Save markdaws/1758429 to your computer and use it in GitHub Desktop.
// common.js ======================================
exports.foo = function() {
return 'bar';
}
// ================================================
// anotherfile.js =================================
var common = require('common');
console.log(common.foo());
// ================================================
// when common.js is loaded, node wraps it in a function definition
// and passed in an exports object e.g.
function (exports, require, module, __filename, __dirname) {
exports.foo = function() {
return 'bar';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment