Complete the code to access the request payload in an Express POST route.
app.post('/submit', (req, res) => { const data = req.[1]; res.send(data); });
In Express, the request payload sent in POST requests is accessed via req.body.
Complete the code to parse JSON request bodies in Express.
app.use(express.[1]());To parse JSON payloads in Express, use the built-in express.json() middleware.
Fix the error in accessing the request payload property.
app.post('/data', (req, res) => { const info = req.[1]; res.json(info); });
The correct property to access the request payload is req.body with a lowercase 'b'.
Fill both blanks to create a POST route that reads JSON data and sends a confirmation.
app.post('/submit', express.[1](), (req, res) => { const userData = req.[2]; res.send('Received'); });
Use express.json() middleware to parse JSON, then access data with req.body.
Fill all three blanks to create an Express app that parses URL-encoded data and accesses it in a POST route.
const express = require('express'); const app = express(); app.use(express.[1]({ extended: [2] })); app.post('/form', (req, res) => { const formData = req.[3]; res.json(formData); });
To parse URL-encoded form data, use express.urlencoded({ extended: true }) middleware and access data via req.body.