Tom Oliver's profile picture
Tom Oliver

It's taken me far too long to discover this foot-gun in express.

I started a new express project the other day and realised that my request bodies were all empty! Spent a good hour thinking it was a problem in the client or the proxy etc... but was actually just because I forgot to apply these two middlewares.

So the question is, why are these middlewares not enabled by default????

JS
const app = express()
// this populates req.body when the payload is json
app.use(express.json({ type: "application/json" }))
// this populates req.body when the payload is urlencoded
// (e.g when a form gets submitted)
app.use(express.urlencoded({ extended: true }))
...

Sensible defaults are just something we don't deserve I guess...

No Webmentions for this note yet!