express-fileupload
Simple Express middleware for handling `multipart/form-data` file uploads, built on Busboy.
express-fileupload
ExpressSimple Express middleware for handling `multipart/form-data` file uploads, built on Busboy.
Fit
Bundle (gzip)
8.8 kB
31.9 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Accepting file uploads in Express normally requires wiring up streaming multipart parsing, temporary storage, and manual move-to-disk logic before you can even access the uploaded file.
What It Does
express-fileupload exposes uploaded files on req.files with a convenient mv() helper to save them, plus options for size limits and temp files. It wraps Busboy to make basic upload handling a few lines of code.
Installation
npm install express-fileuploadUsage Example
import express from "express";
import fileUpload from "express-fileupload";
const app = express();
app.use(fileUpload());
app.post("/upload", async (req, res) => {
const file = req.files.avatar;
await file.mv(`./uploads/${file.name}`);
res.json({ saved: file.name, size: file.size });
});
app.listen(3000);Related packages
Node.js body parsing middleware — populate `req.body` from JSON, urlencoded, text, and raw payloads.
compressionExpressHTTP response compression middleware for Express — gzip/deflate responses to reduce bandwidth and improve load times.
cookie-parserExpressCookie parsing middleware for Express — parse Cookie headers into `req.cookies` and support signed cookies for tamper detection.
corsExpressCORS middleware for Express — configure cross-origin resource sharing with a single line of code.
express-async-errorsExpressSimplify Express error handling by automatically passing thrown errors to `next()`.