Node.js
/Beginner
Request & Response Objects
Definition
The enhanced objects provided by Express representing the HTTP request (`req`) and the HTTP response (`res`). Express adds powerful utility methods on top of the raw Node.js objects.
Explain Like I'm New
Express takes the raw, difficult-to-use Node.js `req` and `res` objects and gives them superpowers. Instead of manually turning objects into JSON strings and configuring headers, you just write `res.json(user)`. Express does all the heavy lifting instantly.
Real World Example
Using `req.ip` to find the user's IP address to block a hacker, or using `res.download('report.pdf')` which automatically prompts the user's browser to download a file with one line of code.
Common Use Cases
- •Reading client data
- •Formatting JSON responses
- •Setting cookies
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- What Express method sends a JSON response?
intermediate
- Where does data from an HTML form POST request live in the `req` object?