{"id":13330,"library":"indx","title":"Indx: Require Directory Utility","description":"The `indx` package offers a minimalist utility for Node.js environments, designed to recursively load JavaScript and CoffeeScript files from a specified directory into a single object. It emulates the functionality of Ruby's `require_tree` directive, simplifying the aggregation of modules, particularly for architectural patterns like adapters where numerous small files need to be exposed collectively. The current stable version is `0.2.3`. However, the package has not seen updates in approximately nine years, indicating it is an abandoned project. It exclusively supports CommonJS module syntax and requires subfolders to explicitly contain an `index.js` or `index.coffee` file for them to be included. Due to its age and lack of ongoing maintenance, `indx` may not be compatible with modern Node.js features or best practices, including ES modules.","status":"abandoned","version":"0.2.3","language":"javascript","source_language":"en","source_url":"https://github.com/jenius/indx","tags":["javascript"],"install":[{"cmd":"npm install indx","lang":"bash","label":"npm"},{"cmd":"yarn add indx","lang":"bash","label":"yarn"},{"cmd":"pnpm add indx","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not support ES module `import` syntax.","wrong":"import indx from 'indx';","symbol":"indxFunction","correct":"const indx = require('indx');"},{"note":"`indx` is a function that immediately takes the path argument, not an object with a method.","wrong":"const adapters = indx.load('./adapters');","symbol":"loadDirectory","correct":"const adapters = require('indx')('./adapters');"},{"note":"The function must be called with a path, typically `__dirname` for the current directory.","wrong":"module.exports = require('indx')();","symbol":"loadCurrentDirectory","correct":"module.exports = require('indx')(__dirname);"}],"quickstart":{"code":"const indx = require('indx');\nconst path = require('path');\n\n// Create a dummy directory structure for demonstration\nrequire('fs').mkdirSync(path.join(__dirname, 'adapters'), { recursive: true });\nrequire('fs').writeFileSync(path.join(__dirname, 'adapters', 'adapterA.js'), 'module.exports = { name: \"Adapter A\" };');\nrequire('fs').writeFileSync(path.join(__dirname, 'adapters', 'adapterB.coffee'), 'module.exports = { name: \"Adapter B (Coffee)\" }'); // Note: Requires 'coffeescript' to be installed\nrequire('fs').mkdirSync(path.join(__dirname, 'adapters', 'sub_adapters'), { recursive: true });\nrequire('fs').writeFileSync(path.join(__dirname, 'adapters', 'sub_adapters', 'index.js'), 'module.exports = require(\\'indx\\')(__dirname);');\nrequire('fs').writeFileSync(path.join(__dirname, 'adapters', 'sub_adapters', 'adapterC.js'), 'module.exports = { name: \"Adapter C\" };');\n\n// Load all adapters from the 'adapters' directory\nconst allAdapters = indx(path.join(__dirname, 'adapters'));\n\nconsole.log('Loaded Adapters:', allAdapters);\n// Expected output: { adapterA: { name: 'Adapter A' }, adapterB: { name: 'Adapter B (Coffee)' }, subAdapters: { adapterC: { name: 'Adapter C' } } }\n\n// Clean up dummy files (optional)\n// require('fs').rmSync(path.join(__dirname, 'adapters'), { recursive: true, force: true });","lang":"javascript","description":"Demonstrates how to recursively load all JavaScript and CoffeeScript files from a directory into an object, respecting subfolder indexing."},"warnings":[{"fix":"Ensure your error handling mechanisms are prepared to catch thrown exceptions rather than relying on console output.","message":"Prior to v0.2.2, errors encountered during module loading were logged to the console. Since v0.2.2, `indx` now throws errors with a full stack trace, which can alter error handling logic.","severity":"breaking","affected_versions":"<0.2.2"},{"fix":"Rename files to `.js` or `.coffee` if they are intended to be loaded by `indx`, or use an alternative loading mechanism for other file types.","message":"Indx only processes `.js` and `.coffee` files. Any other file types within the target directories will be ignored and not included in the resulting object.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure all subdirectories intended for recursive loading have a proper `index.js` or `index.coffee` file configured as described in the usage.","message":"For `indx` to recursively load modules from subdirectories, each subfolder must contain an `index.js` or `index.coffee` file at its root, which in turn calls `require('indx')(__dirname)`.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider using a more actively maintained and modern solution for directory-based module loading, especially for new projects. If using `indx`, be prepared for potential compatibility issues.","message":"The project is explicitly noted as 'in development' with 'versioning a little different', and has been abandoned for approximately nine years. This implies a lack of active maintenance, potential incompatibility with modern Node.js versions, and no expectation of new features or bug fixes.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install the `coffeescript` package: `npm install coffeescript`","cause":"`indx` supports CoffeeScript files, but requires the `coffeescript` package to be installed as a peer dependency for them to be processed.","error":"Error: Cannot find module 'coffeescript' (or similar syntax error related to CoffeeScript)"},{"fix":"Add an `index.js` or `index.coffee` file to the root of each subdirectory you wish to include, containing `module.exports = require('indx')(__dirname);`.","cause":"Subdirectories will only be processed by `indx` if they contain an `index.js` or `index.coffee` file that itself calls `require('indx')(__dirname)`.","error":"Object returned by indx is missing expected files from a subdirectory."},{"fix":"Ensure the file in question has a `.js` or `.coffee` extension.","cause":"`indx` only loads `.js` and `.coffee` files. Other file extensions are ignored.","error":"Expected module not found in the loaded object (e.g., `allAdapters.myFile` is undefined)."},{"fix":"Use CommonJS `require()` syntax (e.g., `const indx = require('indx');`). If your project is pure ESM, you may need a wrapper or a different library.","cause":"`indx` is a CommonJS module and cannot be directly imported using ES module `import` syntax in an ES module context.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}