Skip to content

Instantly share code, notes, and snippets.

@almost
Created May 11, 2012 11:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save almost/2659046 to your computer and use it in GitHub Desktop.
Save almost/2659046 to your computer and use it in GitHub Desktop.
index.js that auto-loads other modules in same directory
var fs = require('fs'), path = require('path');
// Load all exported objects into a single module.
fs.readdirSync(__dirname).forEach(function (filename) {
var fullpath = path.join(__dirname, filename), resource,
module;
if (fullpath !== __filename && 'js' === fullpath.split('.').pop() && '.' !== fullpath[0]) {
module = require(fullpath);
exports[filename.split('.')[0]] = module;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment