Socket
Book a DemoInstallSign in
Socket

node-require-dir

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-require-dir

Powered require directory module, allowing recurse and filtering

latest
npmnpm
Version
0.0.6
Version published
Maintainers
2
Created
Source

node-require-dir

Build Status

Alternatives

After taking over this project I discovered require-glob.

It is recommended to use the above project. If you find any similar projects let me know and I'll add them.

Installation

Install with npm:

npm install --save node-require-dir

Example

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);

console.log(directory);
// { firstController: {...}, otherControllers: { secondController: {...} }}

API

requiredir()

var result = requiredir(directoryName, namePredicate, recursive);
  • directoryName: A string containing the name of the directory you want to include.
  • namePredicate: (optional: identity) A function that ommits a module if it returns false. It also lets you modify the module name as presented in the example.
  • recursive: (optional: false) Whether to recursively recurse the contents of the directory;

note that this function is not polymorphic, if you don't want to use a predicate but want to use recursive you must pass an argument, like null or _.identity.

Testing

From the repo root:

npm install
npm test

Credits

This module was originally created and maintained by Juan Cruz Viotti.

FAQs

Package last updated on 10 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts