Deno Refactor TLS Certs Reading

1.0.0Last update Dec 1, 2024
by@lovelindhoni

This codemod updates the usage of TLS certificate loading in Deno by replacing deprecated properties with their new counterparts. In Deno V2, loading certificates directly from files is now deprecated. Instead, you should read the certificates yourself.

Before

const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
const conn = await Deno.connectTls({
hostname: "192.0.2.1",
port: 80,
caCerts: [caCert],
certChain: Deno.readTextFileSync("./server.crt"),
key: Deno.readTextFileSync("./server.key"),
});

After

const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
const conn = await Deno.connectTls({
hostname: "192.0.2.1",
port: 80,
caCerts: [caCert],
cert: Deno.readTextFileSync("./server.crt"),
key: Deno.readTextFileSync("./server.key"),
});

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now