Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
function Deno.connectTls

Establishes a secure connection over TLS (transport layer security) using an optional cert file, hostname (default is "") and port. The cert file is optional and if not included Mozilla's root certificates will be used (see also for specifics)

const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
const conn1 = await Deno.connectTls({ port: 80 });
const conn2 = await Deno.connectTls({ caCerts: [caCert], hostname: "", port: 80 });
const conn3 = await Deno.connectTls({ hostname: "[2001:db8::1]", port: 80 });
const conn4 = await Deno.connectTls({ caCerts: [caCert], hostname: "", port: 80});

Requires allow-net permission.

Create a TLS connection with an attached client certificate.

const conn = await Deno.connectTls({
  hostname: "",
  port: 443,
  certChain: "---- BEGIN CERTIFICATE ----\n ...",
  privateKey: "---- BEGIN PRIVATE KEY ----\n ...",

Requires allow-net permission.