# busboy-body-parser

> Body parsing for multipart/form-data forms in Express.

Latest version **0.3.2** (published 2018-03-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install busboy-body-parser
pnpm add busboy-body-parser
yarn add busboy-body-parser
bun add busboy-body-parser
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2018-03-16 |
| First published | 2014-11-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Maintainers | lennym |
| Keywords | multipart, body-parser, middleware, busboy, express |

## Links

- npm: https://www.npmjs.com/package/busboy-body-parser
- Repository: https://github.com/lennym/busboy-body-parser
- Homepage: https://github.com/lennym/busboy-body-parser#readme
- Issues: https://github.com/lennym/busboy-body-parser/issues
- npm.io page: https://npm.io/package/busboy-body-parser

## Dependencies (4)

- [bl](https://npm.io/package/bl.md) ^1.2.1
- [bytes](https://npm.io/package/bytes.md) ^2.0.0
- [debug](https://npm.io/package/debug.md) ^2.1.0
- [busboy](https://npm.io/package/busboy.md) ^0.2.9

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2018-03-16
- 0.3.1 — 2017-11-10
- 0.3.0 — 2016-12-20
- 0.2.0 — 2016-10-12
- 0.1.0 — 2016-07-15
- 0.0.10 — 2016-02-09
- 0.0.9 — 2015-04-24
- 0.0.8 — 2015-01-06
- 0.0.7 — 2014-11-06
- 0.0.6 — 2014-11-06
- 0.0.5 — 2014-11-06
- 0.0.4 — 2014-11-06
- 0.0.3 — 2014-11-06
- 0.0.2 — 2014-11-06
- 0.0.1 — 2014-11-06

## README

# busboy-body-parser

Body parsing for multipart/form-data forms in Express.

It will add regular fields to req.body as per [body-parser](https://www.npmjs.org/package/body-parser) but will also add uploaded files to `req.files`.

## Install

`npm install busboy-body-parser`

## Usage

### Basic usage

```javascript
const busboyBodyParser = require('busboy-body-parser');
app.use(busboyBodyParser());
```

### Define a file-size limit

This is defined similarly to the `limit` option in [body-parser](https://www.npmjs.org/package/body-parser) but is applied to individual files rather than the total body size.

```javascript
const busboyBodyParser = require('busboy-body-parser');
app.use(busboyBodyParser({ limit: '5mb' }));
```

This limit can be defined as either a number of bytes, or any string supported by [bytes](https://www.npmjs.org/package/bytes) - eg. `'5mb'`, `'500kb'`.

### Uploading multiple files with the same key

The upload of multiple files with the same key is not enabled by default. If you wish to support this you will need to set the `multi` option to true.

```javascript
const busboyBodyParser = require('busboy-body-parser');
app.use(busboyBodyParser({ multi: true }));
```

_Important note_: if `multi` is set to true, then all `req.files[key]` will *always* be an array, irrespective of the nuber of files associated with that key.

## Output

The middleware will add files to `req.files` in the following form:

```
// req.files:
{
    fieldName: {
        data: Buffer("raw file data"),
        name: "upload.txt",
        encoding: "utf8",
        mimetype: "text/plain",
        truncated: false
    }
}
```

If a file has exceeded the file-size limit defined above it will have `data: null` and `truncated: true`:

```
// req.files:
{
    fieldName: {
        data: null,
        name: "largefile.txt",
        encoding: "utf8",
        mimetype: "text/plain",
        truncated: true
    }
}
```

If the `multi` property is set:

```
// req.files:
{
    fieldName: [{
        data: Buffer("raw file data"),
        name: "upload.txt",
        encoding: "utf8",
        mimetype: "text/plain",
        truncated: false
    }]
}
```

## Tests

`npm test`

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