req and res
noun
say it: “REK and REZ” /ˈrɛk ænd ˈrɛz/
The two objects every Express route receives: req holds the request, and res is how the route sends its answer.
What does req and res do?
Every Express handler receives req (the request: params, query, body, headers) and res (to send the response).
app.get('/search', (req, res) => {
res.json({ query: req.query.q });
});
In a sentence
- “The route reads the id from req and answers with res.json().”
- “req and res are the first two parameters of every Express route.”
Level: Apprentice · More Node.js terms at this level
Updated