# import-modules

> Import all modules in a directory

Latest version **3.2.0** (published 2023-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install import-modules
pnpm add import-modules
yarn add import-modules
bun add import-modules
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2023-01-04 |
| First published | 2017-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 137 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | import, require, files, modules, all, directory, folder, js, paths, multiple, index |

## Links

- npm: https://www.npmjs.com/package/import-modules
- Repository: https://github.com/sindresorhus/import-files
- Homepage: https://github.com/sindresorhus/import-files#readme
- Issues: https://github.com/sindresorhus/import-files/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/import-modules

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.2.0 (latest) — 2023-01-04
- 3.1.0 — 2022-03-16
- 3.0.0 — 2022-03-10
- 2.1.0 — 2020-12-20
- 2.0.0 — 2019-10-03
- 1.1.0 — 2017-05-21

## README

# import-modules

> Import all modules in a directory

*This package is intentionally simple. Not interested in more features.*

## Install

```
$ npm install import-modules
```

## Usage

```
.
└── directory
    ├── foo-bar.js
    └── baz-faz.js
```

```js
const importModules = require('import-modules');

const modules = importModules('directory');

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

## API

### importModules(directory?, options?)

#### directory

Type: `string`\
Default: `__dirname`

Directory to import modules from. Unless you've set the `fileExtensions` option, 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`) and snake-style names (`foo_bar`) to camel-case (`fooBar`).

##### fileExtensions

Type: `string[]`\
Default: `['.js', '.json', '.node']`

File extensions to look for. Order matters.

## Related

- [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path
- [import-cwd](https://github.com/sindresorhus/import-cwd) - Import a module from the current working directory
- [import-lazy](https://github.com/sindresorhus/import-lazy) - Import a module lazily

---
_Source: https://npm.io/package/import-modules · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
