📂
File System3M+/wkMIT

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
npm install multer
yarn
yarn add multer
pnpm
pnpm add multer

Import

ESM
import multer from 'multer';

Quick Example

usage
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

Packagemulter
CategoryFile System
Weekly Downloads3M+
LicenseMIT
Installnpm install multer

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.