require-dir-promise
v0.2.0
Published
Promise-based helper to require() directories.
Downloads
1
Readme
require-dir-promise
A promise-based require
for directories, heavily inpired by [require-dir]
(https://github.com/aseemk/requireDir).
Iterates (non-recursively for now) through a directory and requires all
"requirable" files. Unline most synchronous modules, require-dir-promise
returns a collection of promises that can be chained in .then()
, .all()
and other promise calls.
Example
Given this directory structure:
dir
+ a.js
+ b.json
+ c.coffee
+ d.txt
requireDir('./dir')
will return promises with the following contents:
{file: 'a.js', contents: 'Content for file a.js'},
{file: 'b.json', contents: 'Contents of file b.json'}
And if CoffeeScript was registered, {file: 'c.coffee', contents: 'Contents of file c.coffee'}
will also be returned.
Installation
npm install require-dir-promise
Usage
Iterating over the loaded files
var requireDir = require('require-dir-promise');
requireDir('./path/to/dir').map(function(f) {
console.log(f.fileName);
});
License
MIT.