req.secure is a Boolean that is true when Express treats the request as HTTPS. Officially it is a short-hand for req.protocol === 'https'.
Direct TLS to Node sets it from the encrypted socket. Behind a reverse proxy (nginx, a load balancer, Heroku, and so on), enable trust proxy so Express can honor X-Forwarded-Proto. Related: req.protocol and app.set().
Syntax
Read req.secure in your Express.js route handler. Start with this line.
Express
req.secure
req.protocol === 'https'
Call
What it does
req.secure
Primary signature.
req.protocol === 'https'
Related call form.
Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.
GET http://example.com/path?q=1
→ 301 Location: https://example.com/path?q=1
GET https://example.com/
→ 200 Secure OK
How It Works
Gate every request. Middleware runs first and checks !req.secure.
Build the HTTPS URL. Host from req.get('host'), path/query from req.originalUrl.
Redirect and stop.return after res.redirect so later routes do not run.
Secure traffic continues. When req.secure is true, next() reaches the real handler.
Example 3 — Detect HTTPS Behind a Proxy
Terminate TLS at the proxy, then trust one hop so X-Forwarded-Proto is honored.
Express
const express = require('express');
const app = express();
// Trust the first proxy hop (adjust to your network)
app.set('trust proxy', 1);
app.get('/diag', (req, res) => {
res.json({
secure: req.secure,
protocol: req.protocol,
// Proxy often sends: X-Forwarded-Proto: https
});
});
app.listen(3000);
Output
Client → HTTPS → Proxy → HTTP → Express
Header: X-Forwarded-Proto: https
GET /diag
→ 200 { "secure": true, "protocol": "https" }
(Without trust proxy, the same request often shows
secure: false / protocol: "http")
How It Works
TLS ends at the proxy. Express may see a plain HTTP socket from the proxy.
Enable trust.app.set('trust proxy', 1) tells Express to trust one proxy hop.
Read forwarded proto. With trust on, X-Forwarded-Proto: https makes req.protocol'https'.
req.secure follows. Because it is protocol === 'https', it becomes true.
Compatibility
Runtime Support
req.secure is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not have this API.
✓ Server · Express 4 & 5
req.secure
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.secureExpress 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 Boolean that is true when the request is treated as HTTPS. Officially it is equivalent to req.protocol === 'https'.
The TLS connection often terminates at the proxy, so Express sees plain HTTP unless you enable trust proxy and the proxy sends X-Forwarded-Proto: https.
Only when HTTPS is terminated upstream. Direct TLS to Node already makes req.secure true without trust proxy.
Only if your last trusted proxy overwrites X-Forwarded-For, X-Forwarded-Host, and X-Forwarded-Proto. Prefer a hop count or explicit proxy IPs when you can.
No. It is a server-side Express property. Browsers only send HTTP/HTTPS requests to your app.