devnotes.

req.body Property

req.body contains the parsed body of a request. It's undefined by default and gets populated only once a body-parsing middleware — express.json() or express.urlencoded() — has processed the request.

Syntax

req.body

Example

const express = require("express");
const app = express();
const PORT = 4700;

app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.post("/feedback", (req, res) => {
    console.log(req.body);
    res.send("Feedback received");
});

app.listen(PORT, () => console.log(`Listening on ${PORT}`));

Sending { "rating": 5, "comment": "Loved it" } populates req.body with that object.

Handling large bodies

app.use(express.json({ limit: "5mb" }));
app.use(express.urlencoded({ extended: true, limit: "5mb" }));

Common use cases

  1. Reading form submissions (login, registration).
  2. Handling JSON payloads from a frontend or another API.
  3. Reading fields from multi-part uploads (typically paired with multer).
req.body Property | DevNotes