node-query/node_modules/mysql/node_modules/require-all
2014-10-23 10:52:21 -04:00
..
test Add some more node modules for dev/testsing 2014-10-23 10:52:21 -04:00
.npmignore Add some more node modules for dev/testsing 2014-10-23 10:52:21 -04:00
index.js Add some more node modules for dev/testsing 2014-10-23 10:52:21 -04:00
License Add some more node modules for dev/testsing 2014-10-23 10:52:21 -04:00
package.json Add some more node modules for dev/testsing 2014-10-23 10:52:21 -04:00
Readme.md Add some more node modules for dev/testsing 2014-10-23 10:52:21 -04:00

require-all

An easy way to require all files within a directory.

Usage

var controllers = require('require-all')({
  dirname     :  __dirname + '/controllers',
  filter      :  /(.+Controller)\.js$/,
  excludeDirs :  /^\.(git|svn)$/
});

// controllers now is an object with references to all modules matching the filter
// for example:
// { HomeController: function HomeController() {...}, ...}

Advanced usage

If your objective is to simply require all .js and .json files in a directory you can just pass a string to require-all:

var libs = require('require-all')(__dirname + '/lib');