ProvenPin Install

Express 5 + Multer 2 file uploads with limits: working versions (tested 2026-10-15)

Accept multipart file uploads in Express 5 with Multer memory storage, size limits and a MIME type filter.

passed3 passed · 0 failed2026-10-15 12:52 UTC
Status
passed
Last passed
2026-10-15 12:52 UTC
Tests
3 / 3
Language
TypeScript
Runtime
node v22.23.3
pinned versions8
express@5.3.0multer@2.4.0tsx@4.23.15@types/node@24.19.2supertest@7.3.1@types/supertest@7.2.1@types/express@5.0.6@types/multer@2.3.0
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38737894352

The code

Exactly the files that passed. Your agent can pull them with get_recipe("express-multer-upload") (install), or see them on GitHub.

package.json
{
  "name": "express-multer-upload",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "express": "5.3.0",
    "multer": "2.4.0"
  },
  "devDependencies": {
    "tsx": "4.23.15",
    "@types/node": "24.19.2",
    "supertest": "7.3.1",
    "@types/supertest": "7.2.1",
    "@types/express": "5.0.6",
    "@types/multer": "2.3.0"
  }
}
src/app.ts
import express, { type NextFunction, type Request, type Response } from "express";
import multer from "multer";

const upload = multer({
  storage: multer.memoryStorage(),
  limits: { fileSize: 1024 * 1024 }, // 1 MB
  fileFilter: (_req, file, cb) => cb(null, ["image/png", "image/jpeg"].includes(file.mimetype)),
});

export function createApp() {
  const app = express();
  app.post("/avatar", upload.single("avatar"), (req, res) => {
    if (!req.file) return res.status(400).json({ error: "png_or_jpeg_required" });
    res.status(201).json({ name: req.file.originalname, size: req.file.size, type: req.file.mimetype });
  });
  app.use((err: unknown, _req: Request, res: Response, _next: NextFunction) => {
    if (err instanceof multer.MulterError) return res.status(err.code === "LIMIT_FILE_SIZE" ? 413 : 400).json({ error: err.code });
    res.status(500).json({ error: "internal" });
  });
  return app;
}
test/app.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import request from "supertest";
import { createApp } from "../src/app.ts";

test("accepts a small png", async () => {
  const res = await request(createApp()).post("/avatar").attach("avatar", Buffer.from("fakepng"), { filename: "a.png", contentType: "image/png" });
  assert.equal(res.status, 201);
  assert.equal(res.body.size, 7);
});

test("rejects the wrong type", async () => {
  const res = await request(createApp()).post("/avatar").attach("avatar", Buffer.from("hi"), { filename: "a.txt", contentType: "text/plain" });
  assert.equal(res.status, 400);
});

test("rejects files over the limit with 413", async () => {
  const res = await request(createApp()).post("/avatar").attach("avatar", Buffer.alloc(1024 * 1024 + 1), { filename: "big.png", contentType: "image/png" });
  assert.equal(res.status, 413);
  assert.equal(res.body.error, "LIMIT_FILE_SIZE");
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.