req.host is the host derived from the Host HTTP header. In Express 5 it keeps the port when present — for example Host: example.com:3000 yields example.com:3000.
When trust proxy is enabled, Express may read X-Forwarded-Host instead (first value if several are listed). This is a server-side property on the request object.
Syntax
Read req.host in your Express.js route handler. Start with this line.
Express
req.host
Call
What it does
req.host
Primary signature.
Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.
Proxy terminates TLS / public DNS. The app may only see an internal Host.
Enable trust carefully.trust proxy tells Express to use forwarded headers from that hop.
First forwarded host wins. If several values are listed, Express uses the first.
Harden the proxy. Your edge proxy should overwrite spoofed X-Forwarded-* headers from clients.
Compatibility
Runtime Support
req.host 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.host
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.hostExpress on Node.js
Bottom line: On Express 5, req.host keeps the port. Use req.hostname when you only need the name.
Frequently Asked Questions
It is the host derived from the Host header (or X-Forwarded-Host when trust proxy is enabled). In Express 5 it keeps the port when present, for example example.com:3000.
req.host can include the port. req.hostname is the hostname only — Host example.com:3000 yields hostname example.com.
When trust proxy is not false, Express reads X-Forwarded-Host instead of Host. Use that only behind a proxy you trust.
Express 4 incorrectly stripped the port from req.host. Express 5 keeps the port. Prefer Express 5 behavior when you need host:port.
Not blindly. Host and X-Forwarded-Host can be spoofed. Validate against an allowlist when building absolute URLs or tenant routing.