Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

require-directory

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-directory

Recursively iterates over specified directory, requiring each file, and returning a nested hash structure containing those libraries.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is require-directory?

The require-directory npm package allows you to recursively iterate over all the files in a directory and require them. This is useful for automatically loading scripts, such as routes, models, or configurations, without having to manually require each file.

What are require-directory's main functionalities?

Recursively requiring modules in a directory

This feature allows you to require all modules in a directory and its subdirectories. The 'module' variable refers to the current module, and 'require-directory' will load all modules relative to it.

const requireDirectory = require('require-directory');
const modules = requireDirectory(module);

Whitelisting files to require

This feature allows you to specify a regular expression to filter the files to be required. In this example, only files with a '.js' extension will be required.

const requireDirectory = require('require-directory');
const modules = requireDirectory(module, {
  include: /\.js$/
});

Excluding files from being required

This feature allows you to specify a regular expression to exclude certain files from being required. In this example, files ending with '.test.js' will be ignored.

const requireDirectory = require('require-directory');
const modules = requireDirectory(module, {
  exclude: /\.test\.js$/
});

Custom handler for each required module

This feature allows you to provide a custom handler function that is called for each module that is required. In this example, if the exported module is a function, it is invoked.

const requireDirectory = require('require-directory');
const modules = requireDirectory(module, {
  visit: function (obj) {
    if (obj instanceof Function) obj();
  }
});

Other packages similar to require-directory

Keywords

FAQs

Package last updated on 28 Aug 2013

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc