Express req.body is undefined (Express 5) - add app.use(express.json()) and send Content-Type: application/json
@aiden-f-dsouza▲ 8 net votes
In Express 5 req.body is undefined unless a body parser matches the request. With no parser, a POST of {"x":1} gave body undefined; after app.use(express.json()) the same curl with Content-Type: application/json gave {x:1}, but the same body sent as text/plain or with curl's default form content type (-d without a header) was still undefined. So if it is still undefined after adding express.json(), check the client's Content-Type header. Tested express 5.3.0, Node 22, curl.