Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
require-all
Advanced tools
The require-all npm package is a utility that allows you to require all files within a directory. This can be particularly useful for loading all modules in a directory without having to require each one individually.
Require all files in a directory
This feature allows you to require all files in a specified directory. In this example, all files in the 'controllers' directory will be required and stored in the 'controllers' object.
const requireAll = require('require-all');
const controllers = requireAll(__dirname + '/controllers');
Filter files by extension
This feature allows you to filter the files to be required by their extension. In this example, only JavaScript files in the 'controllers' directory will be required.
const requireAll = require('require-all');
const jsFiles = requireAll({
dirname: __dirname + '/controllers',
filter: /(.+\.js)$/
});
Recursive directory loading
This feature allows you to recursively require all files in a directory and its subdirectories. In this example, all files in the 'modules' directory and its subdirectories will be required.
const requireAll = require('require-all');
const modules = requireAll({
dirname: __dirname + '/modules',
recursive: true
});
Map filenames to module names
This feature allows you to map filenames to module names. In this example, the '.js' extension is removed from the filenames when they are used as keys in the 'controllers' object.
const requireAll = require('require-all');
const controllers = requireAll({
dirname: __dirname + '/controllers',
map: function (name, path) {
return name.replace(/\.js$/, '');
}
});
The require-dir package is similar to require-all in that it allows you to require all files in a directory. However, it is less feature-rich and does not support filtering by extension or recursive loading out of the box.
The bulk-require package provides similar functionality to require-all, allowing you to require multiple files at once. It also supports filtering and recursive loading, but its API is slightly different.
The include-all package is another alternative that allows you to include all files in a directory. It offers similar features such as filtering and recursive loading, but it is designed to work well with the Sails.js framework.
An easy way to require all files within a directory.
var controllers = require('require-all')({
directory: __dirname + '/controllers',
filter: /(.+Controller)\.js$/,
});
// controllers now is an object with references to all modules matching the filter
// for example:
// { HomeController: function HomeController() {...}, ...}
FAQs
An easy way to require all files within a directory.
The npm package require-all receives a total of 144,852 weekly downloads. As such, require-all popularity was classified as popular.
We found that require-all demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.