# read-directory

> Read a directory of files

Latest version **3.0.2** (published 2019-07-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install read-directory
pnpm add read-directory
yarn add read-directory
bun add read-directory
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2019-07-14 |
| First published | 2016-05-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 16.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | sethvincent |
| Maintainers | sethvincent, yoshuawuyts |

## Links

- npm: https://www.npmjs.com/package/read-directory
- Repository: https://github.com/sethvincent/read-directory
- Homepage: https://github.com/sethvincent/read-directory#readme
- Issues: https://github.com/sethvincent/read-directory/issues
- npm.io page: https://npm.io/package/read-directory

## Dependencies (5)

- [glob](https://npm.io/package/glob.md) ^7.1.2
- [defaults](https://npm.io/package/defaults.md) ^1.0.3
- [through2](https://npm.io/package/through2.md) ^2.0.3
- [each-async](https://npm.io/package/each-async.md) ^1.1.1
- [static-module](https://npm.io/package/static-module.md) ^3.0.0

## Recent versions

- 3.0.2 (latest) — 2019-07-14
- 3.0.1 — 2018-10-19
- 3.0.0 — 2017-10-22
- 2.1.1 — 2017-10-22
- 2.1.0 — 2017-06-25
- 2.0.0 — 2016-07-29
- 1.2.0 — 2016-05-07
- 1.1.0 — 2016-05-07
- 1.0.0 — 2016-05-05

## README

# read-directory

Read a directory of files.

## Install

```bash
npm install --save read-directory
```

## Examples

### Async example:

```js
var read = require('read-directory')
read('./files', function (err, contents) {
  console.log(contents)
})
```

### Sync example:

```js
var read = require('read-directory')
var contents = read.sync('./files')
```

## Using in the browser with browserify & budo

Use the included [browserify transform module](transform.js) to convert calls to `read.sync` to the contents of the directory.

Note that to use the browserify transform you must use `read.sync`, and the path to the file directory can not be a variable.

### File that will be browserified & transformed:

```js
var path = require('path')
var read = require('read-directory')
var contents = read.sync(path.join(__dirname, 'files'))
```

### Browserify example:

```bash
browserify index.js -t read-directory -o bundle.js
```

### budo example:

```bash
budo index.js:bundle.js -- -t read-directory
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### readDirectory

Read the contents of a directory asynchronously

**Parameters**

-   `dir` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** – The directory to read
-   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
    -   `options.fs` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** – alternate fs implementation, optional
    -   `options.dirnames` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** – include or exclude subdirectory names in keys of returned object
    -   `options.encoding` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** – encoding of files, default: utf8
    -   `options.filter` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** – glob pattern for filtering files, examples: `*.md`, `*.css`
    -   `options.ignore` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** – glob pattern for ignoring files
    -   `options.ignore` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** – array of glob patterns for ignoring files
    -   `options.transform` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** – A function you can use to transform the contents of files after they are read

**Examples**

```javascript
var read = require('read-directory')
read('./files', function (err, contents) {
  console.log(contents)
})
```

### readDirectory.sync

Read the contents of a directory asynchronously

**Parameters**

-   `dir` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** – The directory to read
-   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
    -   `options.fs` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** – alternate fs implementation, optional
    -   `options.dirnames` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** – include or exclude subdirectory names in keys of returned object
    -   `options.encoding` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** – encoding of files, default: utf8
    -   `options.filter` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** – glob pattern for filtering files, examples: `*.md`, `*.css`
    -   `options.ignore` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** – glob pattern for ignoring files
    -   `options.ignore` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** – array of glob patterns for ignoring files
    -   `options.transform` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** – A function you can use to transform the contents of files after they are read

**Examples**

```javascript
var read = require('read-directory')
var contents = read.sync('./files')
```

## License

[MIT](LICENSE.md)

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