# multer-autoreap

> Connect middleware providing auto gc of tmp uploaded files by multer or any multipart middleware.

Latest version **1.0.3** (published 2018-09-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install multer-autoreap
pnpm add multer-autoreap
yarn add multer-autoreap
bun add multer-autoreap
```

## 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 | 1.0.3 |
| Published | 2018-09-30 |
| First published | 2014-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8 |
| Dependencies | 3 |
| Unpacked size | 21.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Joel A. Bair |
| Maintainers | joelbair |
| Keywords | multer, multipart, form-data, express, middleware, gc, reap, reaper |

## Links

- npm: https://www.npmjs.com/package/multer-autoreap
- Repository: https://github.com/joelabair/multer-autoreap
- Homepage: https://github.com/joelabair/multer-autoreap#readme
- Issues: https://github.com/joelabair/multer-autoreap/issues
- npm.io page: https://npm.io/package/multer-autoreap

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [on-finished](https://npm.io/package/on-finished.md) ^2.3.0
- [es6-object-assign](https://npm.io/package/es6-object-assign.md) ^1.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-09-30
- 1.0.2 — 2018-07-18
- 1.0.1 — 2018-07-18
- 1.0.0 — 2018-03-21
- 0.1.3 — 2017-01-26
- 0.1.2 — 2016-09-26
- 0.1.1 — 2016-07-14
- 0.1.0 — 2016-04-25
- 0.0.9 — 2015-06-17
- 0.0.8 — 2014-06-26
- 0.0.7 — 2014-06-26
- 0.0.6 — 2014-06-21
- 0.0.4 — 2014-05-28
- 0.0.2 — 2014-05-28
- 0.0.1 — 2014-05-28

## README

multer-autoreap
===============

Express middleware for reaping uploaded files saved to disk by multer or any multipart middleware propagating the req.files object.  The middleware will automatically remove any uploaded files left in their temporary location upon response end or close.


#### Installation

`$ npm install multer-autoreap`



#### Usage
as app middleware
```js
const express = require('express');
const multer  = require('multer');
const autoReap  = require('multer-autoreap');

let app = express();
app.use(multer({ dest: '/tmp/' }));
app.use(autoReap);
...
```

or attaching to a route / router.

```js
const express = require('express');
const router = express.Router();

const multer  = require('multer');
const autoReap  = require('multer-autoreap');

let app = express();
app.use(multer({ dest: '/tmp/' }));

app.route('/upload-a').post(autoReap, function(req, res, next) {
	res.on('autoreap', function(file) {
		console.log('auto-reaped: ', file);
	});

	res.send('ok');
});

router.use('/upload-b', autoReap, function(req, res, next) {
	res.on('autoreap', function(file) {
		console.log('auto-reaped: ', file);
	});

	res.send('ok');
});
...
```

[Multer](https://github.com/expressjs/multer) is an efficient `multipart/form-data` handling middleware that uses [busboy](https://github.com/mscdex/busboy).  Files encoded in a miltipart request body are piped to a temporary upload location (def: multer options dest ).  This can have the effect of leaving open an attack vector where disk space can be consumed by these temporary files.  Its prudent and generally good form to clean them up.  While [reap](https://github.com/visionmedia/reap) cleans based on age, multer-autoreap cleans them up as soon as the request is done.

#### Options

```js
autoReap.options = {
	reapOnError: true
};
```
* *reapOnError* (boolean) - If an error occurs, continue reaping the file, or no.
```js
var autoReap  = require('multer-autoreap');
autoReap.options.reapOnError = false;
```


#### Events
The middleware will emit an 'autoreap' event on the Response object when removing files.  The event will include the original file object from req.files[].
```js
res.on('autoreap', function(reapedFile) {
	console.log(reapedFile);
});
```

Please report any issues...

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