Express res Object

Beginner
⏱️ 10 min read
📚 Updated: May 2026
🎯 Core concept

What you’ll learn

  • How Express builds and exposes the res object.
  • Which response methods are used most in handlers.
  • How status, headers, and body methods work together.
  • How to avoid sending duplicate responses.

Common res properties and methods

javascript
res.status(code)
res.send(body)
res.json(data)
res.set(field, value)
res.get(field)
res.redirect(path)
1

Return JSON with status code

javascript
app.get('/health', function (req, res) {
  res.status(200).json({
    ok: true,
    service: 'api'
  });
});
2

Set a header and redirect

javascript
app.get('/legacy', function (req, res) {
  res.set('X-Notice', 'Moved route');
  res.redirect(301, '/new-home');
});

⚠️ Common pitfalls

  • Calling multiple final response methods (send, json, end) in one request flow.
  • Forgetting return after early error responses.
  • Trying to set headers after the response has already been sent.

❓ FAQ

res is the outgoing response object used to send data, set headers, and control status codes.
Common methods include res.status(), res.send(), res.json(), res.set(), and res.redirect().
No. You should send exactly one final response per request.
Use res.json() for API responses because it serializes objects and sets JSON content type.
Return after early responses and use clear control flow in async handlers.
Did you know?

The Express res object extends Node’s response object and provides helpers like status, json, send, set, and redirect.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

4 people found this page helpful