multer

noun

say it: “MUL-ter” /ˈmʌltər/

An Express package that receives files uploaded through a form and saves them, with limits on their size.

What does multer do in an Express app?

multer is Express middleware that reads forms sent as multipart/form-data, the kind that carries files. It saves each uploaded file, puts its details in req.file and the text fields in req.body, and its limits refuse files that are too big.

import multer from "multer";

const upload = multer({ dest: "uploads/", limits: { fileSize: 5_000_000 } });

app.post("/photos", upload.single("photo"), (req, res) => {
  res.status(201).json({ saved: req.file.filename, title: req.body.title });
});

In a sentence

  • “The photo contest uses multer to save each entry's picture and read its title.”
  • “multer refused the 12 MB photo because the limit was 5 MB.”

Level: Journeyman · More Node.js terms at this level

Updated