load-dir
v0.0.3
Published
Recursivly load a directory
Downloads
21
Readme
load-dir
Recursively iterate through a directory and apply an iterator to the filepath. Includes shortcut methods for requiring or file reading.
Install
With npm
npm install load-dir
Usage
Node.js
var loadDir = require('load-dir')
// Require all .js files
var lib = loadDir(__dirname + '/lib/', function(fpath) {
if (!!~fpath.indexOf('.js')) return require(fpath)
return false
})
// Run require on all files, will break if non js files
var lib = loadDir.require(__dirname + '/lib/')
// Load all .jade files
var templates = loadDir(__dirname + '/templates/', function(fpath) {
if (!!~fpath.indexOf('.jade')) return fs.readFileSync(fpath, 'utf8')
return false
})
// Load every file found
var templates = loadDir.fs(__dirname + '/templates/')