LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What are the req and res objects in an Express handler?

req holds everything about the incoming request, while res is the object you use to build and send the reply.

router.get('/hello', function(req, res) {
    // req - read request data
    // res - build response
});

Common res methods:

Method Purpose
res.send(data) Send response and end
res.status(code) Set HTTP status code
res.type(mime) Set Content-Type header
res.write(data) Append to response body

Example:

router.get('/api/data', function(req, res) {
    res.type('application/json');
    res.status(200);
    res.send('{"message": "Hello"}');
});

Tip: res.send() automatically ends the response. Use res.write() + res.end() for streaming.

From Quiz: WEBT / Backend Development | Updated: Jul 14, 2026