Powered require directory module, allowing recurse and filtering


Install with npm:

npm install --save node-require-dir
var requiredir = require('node-require-dir');
var path = require('path');
var directory = requiredir(path.join(__dirname, 'directory'), function(name, module) {
  // Ommit json files
  if(path.extname(name) === '.json') return false;
  // Remove extension and append Controller
  return path.basename(name, path.extname(name)) + 'Controller';
  // Recursive
}, true);
// { firstController: {...}, otherControllers: { secondController: {...} }}
var result = requiredir(directoryName, namePredicate, recursive);
  • directoryName: A string containing the name of the directory you want to include.
  • namePredicate: A function that ommits a module if it returs false. It also lets you modify the module name as presented in the example.
  • recursive: Whether to recursively recurse the contents of the directory;

From the repo root:

npm install
npm test