{"library":"requireindex","title":"Directory-based Module Auto-Loader","description":"requireindex is a utility for Node.js CommonJS environments that simplifies the creation of `index.js` files by automatically requiring and exporting sibling modules within a directory. It aggregates modules into a single object, with keys corresponding to file basenames. It supports nested directories, allows explicit file inclusion, and respects a convention for private modules (prefixing with an underscore). The current stable version is 1.2.0, which was last published over 8 years ago, indicating the package is no longer actively maintained. It offers a concise alternative to manually writing multiple `require()` statements for structuring CommonJS projects, though its relevance has diminished with the widespread adoption of ES Modules.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install requireindex"],"cli":null},"imports":["const requireIndex = require('requireindex');","module.exports = require('requireindex')(__dirname);","module.exports = require('requireindex')(__dirname, ['file1', 'file2']);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const fs = require('fs');\nconst path = require('path');\n\n// Create a temporary directory structure for demonstration\nconst tempDir = path.join(__dirname, 'temp_modules');\nfs.mkdirSync(tempDir, { recursive: true });\nfs.writeFileSync(path.join(tempDir, 'moduleA.js'), 'module.exports = { a: 1 };');\nfs.writeFileSync(path.join(tempDir, 'moduleB.js'), 'module.exports = { b: 2 };');\nfs.writeFileSync(path.join(tempDir, '_privateModule.js'), 'module.exports = { private: true };');\n\n// Emulate index.js in temp_modules\nconst requireIndex = require('requireindex');\nconst modules = requireIndex(tempDir);\n\nconsole.log('Discovered modules:', modules);\n// Expected output: { moduleA: { a: 1 }, moduleB: { b: 2 } }\n\n// Clean up temporary directory\nfs.unlinkSync(path.join(tempDir, 'moduleA.js'));\nfs.unlinkSync(path.join(tempDir, 'moduleB.js'));\nfs.unlinkSync(path.join(tempDir, '_privateModule.js'));\nfs.rmdirSync(tempDir);\n","lang":"javascript","description":"Demonstrates how to use `requireindex` to automatically load and export modules from a directory, including showing how it ignores files prefixed with an underscore.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}