Davide ae94b68904 _archives: archive unmaintained nodejs-dire | 1 vuosi sitten | |
---|---|---|
.. | ||
README.md | 1 vuosi sitten | |
index.js | 1 vuosi sitten |
dire (DIrectory REquire) is a simple node.js module capable of requiring an entire directory of other modules.
var dire = require('dire');
var x = dire('/path/to/some/directory/');
This is the simplest use case. It requires any loadable node.js files in that directory and returns a nested object. If /path/to/some/directory
had the following structure:
/path/to/some/directory/
'-- a/
'-- cfg.json
'-- mod.js
'-- b/
'-- cfg.json
'-- mod.js
'-- err.js
'-- completelyrandommodule.js
the object x
would be:
{
a: {
cfg: [...],
mod: [...]
},
b: {
cfg: [...],
mod: [...],
err: [...],
completelyrandommodule: [...]
}
}
dire
can also be told to load a flat object:
var x = dire('/path/to/some/directory/', true);
and then x
would be:
{
'a/cfg': [...],
'a/mod': [...],
'b/cfg': [...],
'b/mod': [...],
'b/err': [...],
'b/completelyrandommodule': [...]
}
The third parameter provided to dire
specifies the file extension filter:
var x = dire('/path/to/some/directory/', false, '.json');
The value of x
would now be:
{
a: {
cfg: [...]
},
b: {
cfg: [...]
}
}
This module is largely inspired by Troy Goode's node-require-directory
Thanks to @romanshestilovski (github) for spotting and fixing the local path bug.