multer
Node.js middleware for handling multipart/form-data — the standard solution for file uploads in Express and Fastify apps.
multer
Node.jsNode.js middleware for handling multipart/form-data — the standard solution for file uploads in Express and Fastify apps.
Fit
Bundle (gzip)
45.6 kB
235.0 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
HTTP file uploads arrive as multipart/form-data, a binary encoding that requires parsing outside the standard express.json() middleware. Handling file size limits, type validation, and disk vs. memory storage adds significant complexity.
What It Does
Multer parses multipart requests and provides uploaded files on req.file (single) or req.files (multiple). Storage engines let you save to disk with configurable naming or keep files in memory. File filter callbacks reject uploads that don't match your type or size requirements.
Installation
npm install multer
npm install -D @types/multerUsage Example
import multer from 'multer';
import express from 'express';
const upload = multer({
dest: 'uploads/',
limits: { fileSize: 5 * 1024 * 1024 }, // 5 MB
fileFilter: (req, file, cb) => {
cb(null, file.mimetype.startsWith('image/'));
},
});
const app = express();
app.post('/avatar', upload.single('avatar'), (req, res) => {
console.log(req.file); // { fieldname, originalname, size, path, ... }
res.json({ path: req.file?.path });
});Related packages
Role and attribute based access control (RBAC + ABAC) for Node.js with a fluent, readable API.
bcryptjsNode.jsPure JavaScript bcrypt password hashing — no native dependencies, same API as bcrypt, works anywhere Node.js runs.
bullmqNode.jsPremium message queue and job scheduler for Node.js backed by Redis — reliable background job processing with retries, priorities, and rate limiting.
casbinNode.jsA powerful authorization library that supports RBAC, ABAC, ACL and more via configurable policy models.
dotenvNode.jsLoad environment variables from a `.env` file into `process.env` — the standard way to manage configuration in Node.js apps.