Q10: What is the purpose of `express.json()` and `express.urlencoded()`?
Both are built-in body parsing middleware functions introduced in Express 4.16+ (re-integrated from body-parser).
express.json(): Parses incoming HTTP requests carryingapplication/jsonpayload headers and populatesreq.bodywith a JavaScript object.express.urlencoded({ extended: true }): Parses incoming request payloads carryingapplication/x-www-form-urlencodedheaders (standard HTML forms). Theextended: trueoption uses theqslibrary allowing nested object parsing.
Key Takeaways
- Body parsers read raw incoming stream buffers and format them into
req.body. extended: truepermits parsing deeply nested form payloads.