How do you parse JSON bodies in Express?
Add app.use(express.json()) before your routes. req.body is then the parsed JSON object for any request with Content-Type: application/json.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Express.js Server Interview Questions and Answers
A function (req, res, next) that runs on every request. It can modify req, send a response, or call next. Examples: json parsing, auth, logging, error handling.
Register an error-handling middleware at the end with four parameters: (err, req, res, next) => {}. In handlers, throw or call next(err). Use a custom ApiError class. Use an async wrapper to catch promise rejections.
app is the Express application. router is a mini-app you mount with app.use('/path', router). Routers group routes by feature (auth, user, feed). You can mount many routers on one app.
Still have questions?
Browse all our FAQs or reach out to our support team
