Why do async handlers need a wrapper in Express 4?
Express 4 does not catch promise rejections from async handlers automatically. An asyncHandler wrapper catches the promise and passes errors to next. Express 5 catches async errors automatically, but the wrapper is still useful for older versions.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Request Handlers in Express: req, res, and next Explained
req is the incoming request (body, params, query, headers, cookies). res is the outgoing response (status, json, send, cookie, redirect). next passes control to the next middleware or handler, or to the error handler with next(err).
Add app.use(express.json()) before routes, then read req.body. It is the parsed JSON object for any request with Content-Type: application/json.
Use res.cookie(name, value, options) before sending the response. For JWT, set httpOnly: true, secure: true, sameSite: 'lax'. Clear with res.clearCookie(name).
Still have questions?
Browse all our FAQs or reach out to our support team
