express.json()
noun
say it: “ik-SPRES dot JAY-sun” /ɪkˈsprɛs dɑt ˈdʒeɪsən/
Express middleware that reads JSON request bodies and puts the result in req.body.
What does express.json() do?
express.json() is built-in middleware that parses JSON request bodies into req.body.
app.use(express.json());
app.post('/recipes', (req, res) => res.status(201).json(req.body));
In a sentence
- “Without express.json(), req.body was undefined in the POST route.”
- “Add app.use(express.json()) before the routes that read a body.”
Level: Apprentice · More Node.js terms at this level
Updated