Last active
December 18, 2016 00:47
-
-
Save curtiszimmerman/a7305694d7469e27ba69737dc2b64486 to your computer and use it in GitHub Desktop.
A super-simple example of typical module.exports usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// app.js | |
// main application | |
// @author curtiszimmerman | |
// @contact [email protected] | |
// @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); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// foo.js | |
// primary application driver library | |
// @author curtiszimmerman | |
// @contact [email protected] | |
// @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