Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function listenAndServeTls
Deprecated
Deprecated

Use serveTls instead.

Constructs a server, creates a listener on the given address, accepts incoming connections, upgrades them to TLS, and handles requests on these connections with the given handler.

If the port is omitted from the ListenOptions, port 443 is used.

If the host is omitted from the ListenOptions, the non-routable meta-address 0.0.0.0 is used.

import { listenAndServeTls } from "https://deno.land/std@0.132.0/http/server.ts";

const port = 4505;
const certFile = "/path/to/certFile.crt";
const keyFile = "/path/to/keyFile.key";

console.log("server listening on http://localhost:4505");

await listenAndServeTls({ port }, certFile, keyFile, (request) => {
const body = `Your user-agent is:\n\n${request.headers.get(
"user-agent",
) ?? "Unknown"}`;

return new Response(body, { status: 200 });
});
import { listenAndServeTls } from "https://deno.land/std@0.132.0/http/server.ts";

Parameters

config: Partial<Deno.ListenOptions>

The Deno.ListenOptions to specify the hostname and port.

certFile: string

The path to the file containing the TLS certificate.

keyFile: string

The path to the file containing the TLS private key.

handler: Handler

The handler for individual HTTP requests.

optional
options: ServeInit

Optional serve options.

Returns

Promise<void>