Deno standard library
Go to Latest
function listenAndServeTls
import { listenAndServeTls } from "";

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 address, :443 is used.

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

import { listenAndServeTls } from "";

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

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

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

  return new Response(body, { status: 200 });


addr: string

The address to listen on.

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.

options: ServeInit

Optional serve options.