0
const express = require("express");
const { PORT } = require("./config/config");

const setupAndStartServer = async () => {
    const app = express();

    app.get("/", (req, res) => {
        console.log(req.body);
        return res.status(200).json({ data: "Hello" });
    });

    app.listen(PORT, () => {
        console.log(`Server started at ${PORT}`);
    });
};

setupAndStartServer();

console.log(req.body) outputs undefined.

I know that we have to use body-parser and we will be able to read the body. But I want to know the reason Why we can't directly access it without parsing the request body.

Thomas
  • 174,939
  • 50
  • 355
  • 478

0 Answers0