https
To use the HTTPS client-side methods (https.get
, https.request
, etc.), you must enable the enable_nodejs_http_modules
compatibility flag in addition to the nodejs_compat
flag.
This flag is automatically enabled for Workers using a compatibility date of 2025-08-15
or later when nodejs_compat
is enabled. For Workers using an earlier compatibility date, you can manually enable it by adding the flag to your wrangler.toml
:
compatibility_flags = ["nodejs_compat", "enable_nodejs_http_modules"]
To use the HTTPS server-side methods (https.createServer
, https.Server
, https.ServerResponse
), you must enable the enable_nodejs_http_server_modules
compatibility flag in addition to the nodejs_compat
flag.
This flag is automatically enabled for Workers using a compatibility date of 2025-09-01
or later when nodejs_compat
is enabled. For Workers using an earlier compatibility date, you can manually enable it by adding the flag to your wrangler.toml
:
compatibility_flags = ["nodejs_compat", "enable_nodejs_http_server_modules"]
To use both client-side and server-side methods, enable both flags:
compatibility_flags = ["nodejs_compat", "enable_nodejs_http_modules", "enable_nodejs_http_server_modules"]
An implementation of the Node.js https.Agent
↗ class.
An Agent ↗ manages HTTPS connection reuse by maintaining request queues per host/port. In the Workers environment, however, such low-level management of the network connection, ports, etc, is not relevant because it is handled by the Cloudflare infrastructure instead. Accordingly, the implementation of Agent
in Workers is a stub implementation that does not support connection pooling or keep-alive.
import { Agent } from "node:https";import { strictEqual } from "node:assert";
const agent = new Agent();strictEqual(agent.protocol, "https:");
An implementation of the Node.js https.get
↗ method.
The get
method performs a GET request to the specified URL and invokes the callback with the response. This is a convenience method that simplifies making HTTPS GET requests without manually configuring request options.
import { get } from "node:https";
export default { async fetch() { const { promise, resolve, reject } = Promise.withResolvers(); get("https://example.com", (res) => { let data = ""; res.setEncoding("utf8"); res.on("data", (chunk) => { data += chunk; }); res.on("error", reject); res.on("end", () => { resolve(new Response(data)); }); }).on("error", reject); return promise; },};
An implementation of the Node.js https.request
↗ method.
The request
method creates an HTTPS request with customizable options like method, headers, and body. It provides full control over the request configuration and returns a writable stream ↗ for sending request data.
The request method accepts all options from http.request
with some differences in default values:
protocol
: defaulthttps:
port
: default443
agent
: defaulthttps.globalAgent
import { request } from "node:https";import { strictEqual, ok } from "node:assert";
const req = request( "https://developers.cloudflare.com/robots.txt", { method: "GET", }, (res) => { strictEqual(res.statusCode, 200); let data = ""; res.setEncoding("utf8"); res.on("data", (chunk) => { data += chunk; }); res.on("end", () => { ok(data.includes("User-agent")); }); },);req.end();
The following additional options are not supported: ca
, cert
, ciphers
, clientCertEngine
(deprecated), crl
, dhparam
, ecdhCurve
, honorCipherOrder
, key
, passphrase
, pfx
, rejectUnauthorized
, secureOptions
, secureProtocol
, servername
, sessionIdContext
, highWaterMark
.
An implementation of the Node.js https.createServer
↗ method.
The createServer
method creates an HTTPS server instance that can handle incoming secure requests. It's a convenience function that creates a new Server
instance and optionally sets up a request listener callback.
import { createServer } from 'node:https';import { httpServerHandler } from 'cloudflare:node';
const server = createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello from Node.js HTTPS server!');});
server.listen(8080);export default httpServerHandler({ port: 8080 });
The httpServerHandler
function integrates Node.js HTTPS servers with the Cloudflare Workers request model. When a request arrives at your Worker, the handler automatically routes it to your Node.js server running on the specified port. This bridge allows you to use familiar Node.js server patterns while benefiting from the Workers runtime environment, including automatic scaling, edge deployment, and integration with other Cloudflare services.
An implementation of the Node.js https.Server
↗ class.
The Server
class represents an HTTPS server and provides methods for handling incoming secure requests. It extends the Node.js EventEmitter
class and can be used to create custom secure server implementations.
import { Server } from 'node:https';import { httpServerHandler } from 'cloudflare:node';
const server = new Server((req, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ message: 'Hello from HTTPS Server!' }));});server.listen(8080);export default httpServerHandler({ port: 8080 });
The following differences exist between the Workers implementation and Node.js:
- Connection management methods such as
closeAllConnections()
andcloseIdleConnections()
are not implemented - Only
listen()
variants with a port number or no parameters are supported:listen()
,listen(0, callback)
,listen(callback)
, etc. - The following server options are not supported:
maxHeaderSize
,insecureHTTPParser
,keepAliveTimeout
,connectionsCheckingInterval
- TLS/SSL-specific options such as
ca
,cert
,key
,pfx
,rejectUnauthorized
,secureProtocol
are not supported in the Workers environment
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark