req.body holds the parsed body of an incoming request. It stays undefined until a
body-parsing middleware — express.json() or express.urlencoded() — runs first.
const express = require("express");
const app = express();
app.use(express.json());
app.post("/comments", (req, res) => {
console.log(req.body.text);
res.send("Comment stored");
});
app.listen(4600, () => console.log("Listening on 4600"));
Sending { "text": "Great read!" } as JSON populates req.body.text with that string.
Common uses
- Reading form submissions (login, registration, contact forms).
- Reading JSON payloads sent by a frontend or another service.
- Reading fields from multi-part form data (usually alongside
multerfor file uploads).