multer
Multer is a Node.js middleware for handling multipart/form-data, which is primarily used for uploading files through HTML forms. Built on top of busboy for effi…
Installation
npm install multer
yarn add multer
pnpm add multer
Import
import multer from 'multer';
Quick Example
import express from 'express';
import multer from 'multer';
const upload = multer({
dest: 'uploads/',
limits: { fileSize: 5 * 1024 * 1024 },
});
const app = express();
app.post('/upload', upload.single('avatar'), (req, res) => {
console.log(req.file);
res.json({ filename: req.file.filename });
});About multer
Multer is a Node.js middleware for handling multipart/form-data, which is primarily used for uploading files through HTML forms. Built on top of busboy for efficient multipart parsing, Multer adds uploaded files to the request object as req.file (single file) or req.files (multiple files), along with the text fields as req.body. The library provides configurable storage engines: DiskStorage saves files to the local filesystem with custom filename and destination functions, and MemoryStorage holds files in memory as Buffer objects for processing or forwarding to cloud storage. Multer supports file filtering through a fileFilter function that accepts or rejects files based on mimetype, original name, or custom logic, and configurable limits for file size, number of files, number of fields, and field name length. The middleware provides specific upload methods: upload.single('avatar') for one file, upload.array('photos', 10) for multiple files on one field, and upload.fields([{ name: 'avatar' }, { name: 'gallery', maxCount: 8 }]) for files on multiple fields. Multer is the standard file upload middleware for Express applications and integrates with cloud storage services through community storage engines for S3, Google Cloud Storage, and Azure Blob Storage.
Quick Facts
| Package | multer |
| Category | File System |
| Weekly Downloads | 3M+ |
| License | MIT |
| Install | npm install multer |
Related Packages
Formidable is a Node.js module for parsing form data, especially file uploads. Unlike Multer which i…
Express is the most widely used web application framework for Node.js, providing a minimal and flexi…
Sharp is the highest-performance Node.js image processing library, using the libvips image processin…
fs-extra is a drop-in replacement for Node.js's built-in fs module that adds additional file system …
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.