indexjs
You can use indexjs to simplify the requiring of similar modules within a directory, for examples models;
API
indexjs(directory, output, [transform])
directory will usually be __dirname, when run from index.js of a directory.
output can be either an array or an object, it doesn't have to be empty.
transform is an optional function that gets called on all the required modules, the return value is used instead of the module
Usage
File structure
-- app.js
-- models/
----- index.js
----- user.js
----- comment.js
----- post.js
----- .hiddenfile
-- routers/
----- index.js
----- user.js
----- comment.js
----- post.js
models/index.js
/** * /project/models/index.js */ var indexjs = ;moduleexports = ;
routers/index.js
/** * /project/routers/index.js */ var indexjs = ;moduleexports = ;
app.js
/** * /project/app.js */ var models = ;var routers = ;routers; modelsuser; // the equivalent of require('./models/user');modelscomment; // the quivalent of require('./models/comment');// etc..models'.hiddenfile'; // undefined;