Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

req-all

sindresorhus777.1kMITdeprecated2.0.0

Renamed to import-modules.

Require all files in a directory

require, files, modules, all, directory, dir, folder, js, paths, multiple, index

readme

req-all Build Status

Require all files in a directory

This module is intentionally simple. Not interested in more features.

Install

$ npm install --save req-all

Usage

.
└── dir
    ├── foo-bar.js
    └── baz-faz.js
const reqAll = require('req-all');
const modules = reqAll('dir');

console.log(modules);
//=> {fooBar: [Function], bazFaz: [Function]}

API

reqAll([directory], [options])

directory

Type: string
Default: __dirname

Directory to require supported files in. Unless you've modified require.extensions, that means any .js, .json, .node files, in that order. Does not recurse. Ignores the caller file and files starting with . or _.

options

Type: Object

camelize

Type: boolean
Default: true

Convert dash-style names (foo-bar) to camel-case (fooBar).

License

MIT © Sindre Sorhus