Skip to content

Instantly share code, notes, and snippets.

@curtiszimmerman
Last active December 18, 2016 00:47
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 curtiszimmerman/a7305694d7469e27ba69737dc2b64486 to your computer and use it in GitHub Desktop.
Save curtiszimmerman/a7305694d7469e27ba69737dc2b64486 to your computer and use it in GitHub Desktop.
A super-simple example of typical module.exports usage
//// app.js
// main application
// @author curtiszimmerman
// @contact software@curtisz.com
// @license AGPL
// @version 0.0.1
var app = (function() {
// local dependency
var foo = require('./foo.js');
var uno = foo.foo(0);
var dos = foo.bar(uno);
})();
//// foo.js
// primary application driver library
// @author curtiszimmerman
// @contact software@curtisz.com
// @license AGPL
// @version 0.0.1
var foo = module.exports = (function() {
var _foo = function( thing ) {
return ++thing;
};
var _bar = function( stuff ) {
return --stuff;
};
var _init = (function() {
// some initialization stuff which runs automatically when require()'ed
})();
return {
foo: _foo,
bar: _bar
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment