Registry / web-framework / multer-autoreap

multer-autoreap

JSON →
library1.0.3jsnpmunverified

multer-autoreap is an Express middleware designed to automatically clean up temporary files uploaded to disk by `multer` or other `multipart/form-data` parsing middleware. Upon completion of an HTTP request (either success or error, configurable via `reapOnError`), the middleware identifies and deletes files referenced in `req.files` or `req.file` that were stored in temporary locations. The current stable version is 1.0.3, with releases being infrequent but focused on stability and compatibility fixes, particularly with newer Node.js versions and Multer core changes. Its primary differentiator is the immediate, request-lifecycle-driven cleanup, offering a more responsive alternative to age-based file reaping solutions and mitigating potential disk space exhaustion vulnerabilities inherent in handling file uploads.

npm install multer-autoreap
INSTALL
IMPORT
SIG · MULTER-AUTOREAP
M
multer-autoreap
web-frameworkjavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

autoReap
const autoReap = require('multer-autoreap');
import autoReap from 'multer-autoreap';
This package is primarily a CommonJS module. Use `require()` for importing. Direct ES module `import` syntax will not work without a CommonJS wrapper or transpilation.
autoReap.options
const autoReap = require('multer-autoreap'); autoReap.options.reapOnError = true;
import { options } from 'multer-autoreap';
Options are set directly on the imported `autoReap` object, not as named exports.

This quickstart demonstrates setting up an Express server with Multer for file uploads and integrating `multer-autoreap` as global middleware to automatically clean up temporary files after the request finishes. It also shows how to listen for the `autoreap` event on the response object.

const express = require('express'); const multer = require('multer'); const autoReap = require('multer-autoreap'); const app = express(); // Configure Multer to save files to a temporary directory const upload = multer({ dest: './tmp-uploads/' }); // Apply multer-autoreap as a global middleware app.use(autoReap); // Example route for file upload app.post('/upload', upload.single('myFile'), function (req, res, next) { res.on('autoreap', function(file) { console.log('File automatically reaped:', file.filename, 'at', file.path); }); if (!req.file) { return res.status(400).send('No file uploaded.'); } res.send(`File '${req.file.originalname}' uploaded and will be cleaned up.`); }); // Start the server const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server listening on port ${PORT}`); console.log(`Temp upload directory: ${upload.dest}`); console.log('Upload a file via POST to /upload with field name "myFile"'); });
Debug
Known issues
breakingOlder versions of `multer-autoreap` (prior to v0.1.0) may have compatibility issues or unexpected behavior when used with newer Multer versions (Multer >= 1.0.0) due to changes in how `req.files` and `req.file` objects are structured and populated. Ensure you are using `multer-autoreap` v0.1.0 or later for modern Multer setups.
fix
Upgrade `multer-autoreap` to at least version 0.1.0: `npm install multer-autoreap@latest`.
affects: <0.1.0
gotchaBy default (`reapOnError: true`), `multer-autoreap` will attempt to reap (delete) temporary files even if an error occurs during the request processing. If your application's error handling workflow requires temporary files to persist for debugging, analysis, or retry mechanisms, you must explicitly disable this behavior.
fix
Set `autoReap.options.reapOnError = false;` globally or within a specific middleware chain.
affects: >=0.0.8
gotchaThe order of middleware in Express is crucial. If `multer-autoreap` is placed before your Multer middleware in the chain, it will not find any files in `req.files` or `req.file` to clean up, as Multer will not have processed them yet.
fix
Always ensure `app.use(autoReap)` (or route-specific `autoReap`) comes *after* your Multer configuration, e.g., `app.use(multer({ dest: '/tmp/' })); app.use(autoReap);`.
affects: >=0.0.8
gotchaThis package is primarily a CommonJS module. Attempting to use ES module `import` syntax (`import autoReap from 'multer-autoreap'`) in an ESM-only environment without proper transpilation or a CommonJS wrapper will lead to import errors.
fix
In CommonJS environments, use `const autoReap = require('multer-autoreap');`. In ESM environments, consider dynamic import (`import('multer-autoreap').then(m => m.default)`) or ensure your build setup correctly handles CJS interop.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: autoReap is not a function
Attempting to use `autoReap` as a function or as a named export from an ES module `import` statement.
fix
This package exports a single default CommonJS module. Use `const autoReap = require('multer-autoreap');` to correctly import it.
Files are not being deleted from the temporary upload directory.
This typically happens if `multer-autoreap` is applied before Multer in the middleware chain, or if `autoReap.options.reapOnError` is set to `false` and an error prevents the successful completion of the request.
fix
Verify that `app.use(autoReap)` or the route-specific `autoReap` middleware is placed *after* your Multer file processing middleware. Also, check the `autoReap.options.reapOnError` setting to ensure files are reaped under desired conditions.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
expressrequiredPeer dependency for the web framework integration.
multerrequiredPeer dependency as it's designed to clean up files processed by Multer.
Agent activity
4 hits · last 30 days
node
4
Resources