Express res.get() Method

Beginner
⏱️ 7 min read
📚 Updated: May 2026
🎯 3 Code Examples

What you’ll learn

  • How to read outgoing response headers with res.get().
  • How res.get() differs from req.get().
  • How to use header checks in middleware flow.
  • When header lookups can return undefined.

Syntax

javascript
res.get(field)
1

Read a header after setting it

javascript
app.get('/cache', function (req, res) {
  res.set('Cache-Control', 'public, max-age=60');
  var cacheHeader = res.get('Cache-Control');
  res.json({ cache: cacheHeader });
});
2

Inspect headers in middleware chain

javascript
app.use(function (req, res, next) {
  res.set('X-App-Version', '1.0.0');
  next();
});

app.get('/version', function (req, res) {
  res.send('Version header: ' + res.get('X-App-Version'));
});
3

Handle missing header value safely

javascript
app.get('/content-type-check', function (req, res) {
  var contentType = res.get('Content-Type');
  if (!contentType) return res.type('text').send('Content-Type not set yet');
  res.send('Content-Type: ' + contentType);
});

⚠️ Common pitfalls

  • Do not confuse req.get() (incoming headers) with res.get() (outgoing headers).
  • Expect undefined when reading headers that were never set.
  • Avoid mutating response state after the response has already been sent.

❓ FAQ

It returns the current value of a response header that has been set on res.
No. req.get() reads incoming request headers; res.get() reads outgoing response headers.
You can, but it usually returns undefined if that header has not been set yet.
Avoid relying on response mutations after send/end; inspect or set headers before finishing the response.
Yes, it is useful for checking headers set by earlier middleware before deciding next steps.
Did you know?

res.get(field) reads a response header currently set on the outgoing response object.

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