Registry / devops / export-files

export-files

JSON →
library3.0.2jsnpmunverified

export-files is a Node.js utility designed to automatically export all JavaScript files within a specified directory as modules. It provides a simple mechanism to aggregate multiple source files into a single object, where each file's export becomes a property. The current stable version is 3.0.2, with previous major breaking changes noted in v3.0.0 and v0.2.0. A key differentiator is its exclusive focus on CommonJS `require` syntax, explicitly stating it does not support ES Module `import` statements. It offers robust features like recursive directory processing, file filtering, and customizable key casing for the exported modules, making it suitable for organizing larger Node.js projects into modular structures without manual `require` statements for every file.

npm install export-files
INSTALL
IMPORT
SIG · EXPORT-FILES
E
export-files
devopsjavascriptv3.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

exportFiles
const exportFiles = require('export-files');
import exportFiles from 'export-files';
This library is CommonJS-only and explicitly does not support ES Modules (import/export syntax).
Directory Export
module.exports = require('export-files')(__dirname);
export default require('export-files')(__dirname);
The primary use case is to export an entire directory's contents using Node.js's `module.exports`.
Export with Options
const modules = require('export-files')(__dirname, null, { recursive: true, ignoreDirs: [] });
import { recursive } from 'export-files/options';
Options are passed as the third argument to the main function, not imported separately.

Demonstrates how to use `export-files` to load JavaScript modules from a directory, including nested directories, and access their exports. The example sets up a temporary directory with modules and cleans up afterwards.

const path = require('path'); const fs = require('fs'); const exportFiles = require('export-files'); // 1. Create a dummy directory and files for demonstration const exampleDir = path.join(__dirname, 'temp_example_modules'); const nestedDir = path.join(exampleDir, 'nested'); if (!fs.existsSync(exampleDir)) fs.mkdirSync(exampleDir, { recursive: true }); if (!fs.existsSync(nestedDir)) fs.mkdirSync(nestedDir, { recursive: true }); fs.writeFileSync(path.join(exampleDir, 'utilA.js'), `module.exports = { getA: () => 'Value from utilA' };`); fs.writeFileSync(path.join(exampleDir, 'utilB.js'), `module.exports = { getB: (name) => \`Hello, \${name} from utilB\` };`); fs.writeFileSync(path.nestedDir, 'utilC.js'), `module.exports = { getC: () => 'Value from nested utilC' };`); // 2. Use export-files to load the modules const modules = exportFiles(exampleDir, undefined, { recursive: true }); console.log('Exported module keys:', Object.keys(modules)); // Expected output: Exported module keys: [ 'utilA', 'utilB', 'utilC' ] console.log('Call utilA.getA():', modules.utilA.getA()); // Expected output: Call utilA.getA(): Value from utilA console.log('Call utilB.getB("World"):', modules.utilB.getB('World')); // Expected output: Call utilB.getB("World"): Hello, World from utilB console.log('Call utilC.getC():', modules.utilC.getC()); // Expected output: Call utilC.getC(): Value from nested utilC // 3. Clean up the dummy directory process.on('exit', () => { if (fs.existsSync(exampleDir)) { fs.rmSync(exampleDir, { recursive: true, force: true }); console.log('Cleaned up temp_example_modules directory.'); } });
Debug
Known issues
breakingVersion 3.0.0 introduced significant breaking changes related to improved support for recursion and renaming keys. Users upgrading from v2.x should review the README for updated options and behavior.
fix
Review the official README for v3.0.0 to understand the new `recursive` and `.case` options, and adjust your usage accordingly.
affects: 3.0.0
breakingVersion 0.2.0 removed support for non-JavaScript files. This library now exclusively handles `.js` files. Functionality for exporting other file types was moved to the `to-exports` package.
fix
Ensure you are only attempting to export `.js` files. For non-JavaScript files, consider using the `to-exports` package.
affects: 0.2.0
gotchaThis library is designed for CommonJS environments only and exclusively uses `require`. It does not support ES Modules (`import` statements). Attempting to use it with `import` will result in runtime errors.
fix
Always use `const module = require('export-files');` syntax. If your project uses ES Modules, you may need to wrap `export-files` in a CommonJS module or re-evaluate your module loading strategy.
affects: >=0.1.0
gotchaThe default `.filter` option excludes files named `index.js`. If you intend to export an `index.js` file from your directory, you must explicitly override this filter.
fix
Pass a custom `filter` function to the options, e.g., `{ filter: file => true }` or `{ filter: file => file.name !== 'another-file.js' }`.
affects: >=0.1.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use ES Modules `import` syntax with the CommonJS-only `export-files` library.
fix
Replace `import exportFiles from 'export-files';` with `const exportFiles = require('export-files');`
TypeError: require(...) is not a function
Incorrectly calling the `export-files` module without passing the required directory path as the first argument.
fix
Ensure you pass the directory path, typically `__dirname`, as the first argument: `require('export-files')(__dirname);`
Error: Cannot find module 'my-non-javascript-file.json'
Attempting to export a non-JavaScript file, which `export-files` no longer supports since v0.2.0.
fix
Ensure that the directory only contains `.js` files you wish to export, or use the `to-exports` package for other file types.
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
export-files — npm install export-files · libregistry