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.
Express.js Server Interview Questions and Answers
What is the difference between app and router in Express?
The answer
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.
Add app.use(express.json()) before your routes. req.body is then the parsed JSON object for any request with Content-Type: application/json.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.