In Express.js, req.protocol is a string with the request protocol: http, or https for TLS. Example: console.dir(req.protocol) // => 'http'.
When trust proxy is enabled, Express may use the X-Forwarded-Proto header from your reverse proxy. Configure trust with app.set('trust proxy', …). For a boolean check, use req.secure (protocol === 'https'). See also the Express behind proxies guide pattern.
Syntax
Read req.protocol in your Express.js route handler. Start with this line.
Express
req.protocol
Call
What it does
req.protocol
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.
GET /self?ref=home
Host: www.example.com
X-Forwarded-Proto: https
→ https://www.example.com/self?ref=home
How It Works
Scheme from protocol. Respects trusted forwarded proto.
Host from the header.req.get('host') reads Host (or forwarded host when trusted).
Path from originalUrl. Keeps path + query via req.originalUrl.
Concatenate. One absolute URL string for links or OAuth callbacks.
Compatibility
Runtime Support
req.protocol is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not execute it — they only open http/https connections to your app.
✓ Server · Express 4 & 5
req.protocol
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.protocolExpress 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 with the request protocol: usually 'http' or 'https' for TLS.
When trust proxy is enabled, Express can use the X-Forwarded-Proto header from your reverse proxy. When trust is off, it uses the actual connection protocol.
req.protocol is the string ('http' or 'https'). req.secure is a boolean that is true when protocol is 'https'.
The TLS connection often terminates at the proxy. Without a matching trust proxy setting, Express sees the plain HTTP hop to your app.
No. It is a server-side Express request property. Browsers only send HTTP(S) requests; your app reads req.protocol on the server.