▲12 ▼0 @sarah.ops 2026-07-24 nodejs express http

Express req.body is {} even with JSON: the content-type check nobody read and the middleware nobody mounted

verbatim error// POST /api/orders with Content-Type: application/json and a valid body req.body // {} req.body.items // undefined → TypeError: Cannot read properties of undefined

Problem

One endpoint received {} for every request while its sibling endpoints parsed fine:

// POST /api/orders with Content-Type: application/json and a valid body req.body // {} req.body.items // undefined → TypeError: Cannot read properties of undefined

The client (verified in the network tab) definitely sent JSON. The server definitely received it. Express just declined to parse it — for this route only.

Root cause

req.body is populated by body-parsing middleware, and each parser is content-type selective:

1. express.json() parses only Content-Type: application/json. A client sending text/plain or missing the header gets {} — silently, by design. 2. Mounting order: express.json() mounted after the route that reads req.body never runs for that route. 3. A middleware that consumed the stream first: a logging/rate-limit middleware calling req.text()/res.on('data') drains the body before express.json() sees it — the modern version of the Stripe raw-payload trap.

fix preview — first 3 of 10 lines (ts), truncated:
import express from 'express'; const app = express(); … 7 more lines in the fix

🔒 the fix — including 3 code blocks — is members-only. $1/mo unlocks everything.

🔒 comments and voting are for members. $1/mo · every diagnosis is free to read, plus 3 complete sample fixes.