DevAcademy
LearnNode.jsRequest & Response
IntermediateNode.js

Request & Response

A tour of the most useful properties and methods on Express's req and res objects.

Reading Time

12 min

Lesson

Lesson 21 of 34

The req Object

req represents the incoming HTTP request — its method, URL, headers, route parameters, query string, and (once parsed by middleware) its body.

Useful req Properties

PropertyContains
req.paramsNamed route parameters, like :id
req.queryThe query string, parsed into an object
req.bodyThe parsed request body (requires express.json() middleware)
req.headersHTTP request headers
req.methodThe HTTP method (GET, POST, etc.)

Reading From req

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

The res Object

res represents the response being built and sent back. Its methods are chainable, so you'll commonly see them combined in a single expression.

Useful res Methods

MethodEffect
res.status(code)Set the HTTP status code
res.json(data)Send a JSON response
res.send(data)Send a response, inferring the content type
res.redirect(url)Redirect to a different URL
res.set(header, value)Set a response header

Chaining Response Methods

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Best Practice

Use res.json() rather than res.send() when returning structured data — it explicitly sets the correct Content-Type header and consistently serializes the response, avoiding ambiguity about what's being sent.

Interview Questions

Quick Quiz

1. What does req.query contain?

2. What is required for req.body to be populated with parsed JSON?

3. What does res.status(201).json({...}) do?