require-directory
Recursively iterates over specified directory, require()'ing each file, and returning a nested hash structure containing those modules.
This package has a good security score with no known vulnerabilities.
Community Reviews
Simple utility with significant security and maintenance concerns
The package hasn't been updated since 2015, which is concerning for a filesystem-interaction utility. While the code is simple enough that lack of updates might not indicate bugs, it does mean modern security practices and Node.js patterns aren't reflected. The error handling is minimal - if a required file throws during load, you get a raw exception with potentially sensitive path information exposed.
For controlled scenarios like loading your own plugin architecture where you trust all files, it works fine. But the automatic execution model combined with no input validation makes it risky for anything touching user-controlled directories or deployments where file integrity isn't guaranteed.
Best for: Loading trusted internal module directories in tightly controlled environments where all file contents are verified
Avoid if: You need to load files from user-controlled paths, require security validation, or want actively maintained dependencies
Simple utility with poor TypeScript support and unclear error handling
Error handling is particularly frustrating. When a required file throws during import, the error messages don't always clearly indicate which file failed, making debugging annoying in larger directory structures. The package also silently skips non-JS files, which can lead to confusion when you expect something to be loaded but it isn't.
The documentation is minimal but covers the basics. There are options for filtering, custom naming, and visiting functions, but discovering these requires reading the README carefully. No migration concerns since it hasn't been updated since 2015, though this also means no modern ES module support.
Best for: Legacy CommonJS projects needing simple auto-loading of route handlers or plugin directories where type safety isn't critical.
Avoid if: You're working with TypeScript, ES modules, or need robust error handling and ongoing maintenance.
Simple utility with minimal overhead but lacks production-grade features
The package hasn't been updated since 2015, which isn't necessarily bad for stable code, but it shows in missing features. There's no error handling granularity - if one module fails to load, you get an exception with minimal context about which file caused the problem. No logging hooks, no way to filter files during traversal, and no async support means you're blocking the event loop during startup while recursively requiring potentially dozens of files.
For small projects or dev tools where you just need to auto-load a handful of route handlers or plugins, it works fine. But for anything that needs observability, graceful degradation, or performance optimization, you'll quickly outgrow it. The lack of configuration options means you can't exclude test files, handle optional modules, or implement custom loading logic without forking.
Best for: Simple applications that need to auto-load a small directory of CommonJS modules at startup with minimal configuration.
Avoid if: You need error resilience, observability, async loading, ES module support, or are loading more than a few dozen files.
Sign in to write a review
Sign In