Last active
August 29, 2015 14:07
-
-
Save stringparser/55b4c8ca77baacac382b to your computer and use it in GitHub Desktop.
Boom, require dir
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
var fs = require('fs'); | |
var path = require('path'); | |
var fileList = fs.readdirSync( | |
path.resolve(path.dirname(module.parent.filename), path.basename(__dirname)) | |
).slice(1); | |
exports = module.exports = { }; | |
fileList.forEach(function(fileName){ | |
var name = path.basename(fileName, path.extname(fileName)); | |
exports[name] = require('./'+fileName); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment