Skip to content

Multer

Node.js middleware that handles file uploads sent as multipart/form-data.

Stars
12.1k
Forks
1.2k
Licence
MIT
Language
JavaScript
Last update
4 days ago
Type
Library

What it is

Multer is a middleware for Node.js servers that receives files and text fields sent from HTML forms. Web forms that upload files use the multipart/form-data format, and Multer parses that data so your server code can read the uploaded files and form values. It is built on top of busboy, a parser library, and it is commonly used with Express.

  • Accept a profile picture on a /profile route with upload.single('avatar')
  • Accept several gallery photos with upload.array('photos', 12)
  • Accept multiple named file fields in one form with upload.fields()
  • Accept text-only forms with upload.none() while rejecting unexpected files

Great for

  • Node.js developers adding file upload to an Express app
  • Developers who need to accept single or multiple files per form field
  • Teams that want uploaded files saved to disk or kept in memory
  • Developers who want control over how uploaded files are named and stored

Not ideal for

  • Projects not using Node.js, since this is a JavaScript middleware
  • Apps that only accept non-multipart requests, because Multer does not process any form that is not multipart/form-data
  • Developers who want Multer applied globally, since the README warns that global use lets users upload files to routes you did not anticipate
Step-by-step guide: how to use MulterInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js · npm

    Install Multer from npm

    npm install multer
  2. 2

    Run it

    • Install Multer with npm install multer.
    • Add enctype="multipart/form-data" to your HTML form.
    • Create an upload instance with multer({ dest: 'uploads/' }).
    • Add upload.single('fieldname') or another method to your POST route and read req.file or req.files.
  3. 3

    Get the most out of it

    • Use the storage option with DiskStorage to control destination and filename, as shown in the README.
    • Use fileFilter to control which files are accepted.
    • Use limits.files and maxCount to bound how many files are accepted.
    • Use preservePath only if you need client folder paths, and validate file.originalname before using it.
    • Review the examples/ folder for browser FormData upload examples.

Downloads

Strengths

  • Simple, short setup: install from npm and add it as route middleware
  • Supports single, array, multi-field, and text-only upload patterns
  • Lets you choose between disk storage, memory storage, or a custom storage engine

Trade-offs

  • The README says file.originalname is client-supplied and must be validated, so safe handling is your responsibility
  • Files are stored in memory by default if no dest or storage is set, which the README describes but which may matter for large uploads
  • Only works for multipart requests; other body formats are not handled

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.