Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Apr 8, 2024 via pnpm

require-directory 2.1.1

Recursively iterates over specified directory, require()'ing each file, and returning a nested hash structure containing those modules.
Package summary
Share
0
issues
1
license
1
MIT
Package created
27 Dec 2011
Version published
28 May 2015
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
require-directory@2.1.1
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
ⓘ This is a list of require-directory 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does require-directory do?

Require-Directory is a substantial npm package in the node.js environment. It provides an automatic approach to loop over a specified directory recursively, invoking the require() function on each file it finds, and returning a nested hash structure of the required modules. This process ensures all modules in the stipulated directory are loaded and made accessible, thus simplifying the module retrieval process in complex projects.

How do you use require-directory?

For using Require-Directory, we start by installing it via npm using the command npm install require-directory. The main usage pattern in node.js involves implementing an index file that generates a hash of the files in its directory. Here is an illustrative usage example:

var requireDirectory = require('require-directory');
module.exports = requireDirectory(module);

The above code uses Require-Directory to build a hash of modules in the directory. Later, in your desired application file (like app.js), you can require the constructed hash object. Here’s how:

var routes = require('./routes');

// other code

app.get('/', routes.home);
app.get('/register', routes.auth.register);
app.get('/login', routes.auth.login);
app.get('/logout', routes.auth.logout);

In the code snippet above, routes is equivalent to

var routes = {
  home: require('routes/home.js'),
  auth: {
    login: require('routes/auth/login.js'),
    logout: require('routes/auth/logout.js'),
    register: require('routes/auth/register.js')
  }
};

Require-Directory also gives you an option to require another directory by passing it as a second parameter. Additionally, you can pass an options hash as the second or third parameter for settings related to file inclusion, exclusion, visiting objects, renaming keys, and recursion.

Where are the require-directory docs?

The official documentation for Require-Directory, including its installation guide, usage examples, options, and unit tests, can be found in the readme file of its GitHub repository. For a more extensive knowledge, visit its repository via the URL git://github.com/troygoode/node-require-directory.git.