req.subdomains is a string array of subdomain labels from the request hostname. Express takes req.hostname, splits on dots, and drops the trailing “main domain” labels controlled by subdomain offset (default 2).
Official example: Host tobi.ferrets.example.com → ['ferrets', 'tobi']. Index 0 is closest to the apex domain. Useful for multi-tenant apps (acme.example.com → tenant acme).
Syntax
Read req.subdomains in your Express.js route handler. Start with this line.
This Express.js property is read from the request or response — it has no call parameters.
Return Value
req.subdomains is a read-only array of subdomain labels from the hostname. It returns [] when there is no hostname or nothing left after the subdomain offset.
GET / Host: acme.example.com
→ 200 Hello, acme
GET / Host: unknown.example.com
→ 404 Unknown tenant
GET / Host: example.com
→ 404 Unknown tenant (subdomains is [])
How It Works
Take the first label. With default offset, acme.example.com → ['acme'].
Allowlist tenants. Only known names continue; others get 404.
Attach context.req.tenant is available to later handlers.
Apex has no tenant. Bare example.com yields an empty array — handle that path separately if needed.
Compatibility
Runtime Support
req.subdomains is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send the Host header.
✓ Server · Express 4 & 5
req.subdomains
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.
ServerNode.js runtime API
Node.js18+ for Express 5 · 14+ typical for Express 4
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
req.subdomainsExpress on Node.js
Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.
Frequently Asked Questions
It is a String array of subdomain labels from the request hostname. For Host tobi.ferrets.example.com with the default offset, it is ['ferrets', 'tobi'].
An app setting (default 2) that tells Express how many trailing host labels are the “main domain” (for example example.com). Labels before that are returned as subdomains.
Use app.set('subdomain offset', n). Use 3 for domains like example.co.uk where the public suffix has three labels.
Indirectly. req.subdomains is derived from req.hostname, which can use X-Forwarded-Host when trust proxy is enabled.
No. It is a server-side Express property. Browsers only send the Host (or forwarded host) header.