Express req.subdomains Property

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

What you’ll learn

  • How to read and interpret req.subdomains.
  • How subdomain offset changes parsing.
  • How to route traffic by tenant subdomain.
  • How proxy and host settings impact subdomain detection.

Usage syntax

javascript
req.subdomains
app.set('subdomain offset', 2)
1

Read subdomain array from host

javascript
app.get('/tenant', function (req, res) {
  res.json({ subdomains: req.subdomains });
});
2

Adjust subdomain offset for custom domains

javascript
app.set('subdomain offset', 3);

app.get('/who', function (req, res) {
  res.send('Tenant: ' + (req.subdomains[0] || 'none'));
});

❓ FAQ

It is an array of subdomain segments parsed from the request host.
It uses the subdomain offset setting to ignore top-level domain segments.
By default Express uses offset 2 (common for domains like example.com).
Yes. Use app.set('subdomain offset', value) for your domain structure.
Yes, it is often used to resolve tenant context from subdomain-based URLs.
Did you know?

req.subdomains returns subdomain parts from the host name, controlled by Express subdomain offset.

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