---
name: node-quic-dtls
description: "QUIC, HTTP/3 and DTLS in Node.js with node:quic and node:dtls. Use for QUIC connections or streams, HTTP/3, unreliable datagrams, DTLS over UDP, IoT/CoAP with pre-shared keys, or WebRTC DTLS-SRTP keying. Covers quic.connect/listen, QuicEndpoint/QuicSession/QuicStream, sendDatagram, dtls.listen/connect, PSK, SNI, session resumption, --experimental-quic and --experimental-dtls. Needs a Node.js built with QUIC/DTLS support (standard release builds lack it). QUIC 24.16+/26.x, DTLS 26.9+."
title: node-quic-dtls
canonical_url: https://skilld.dev/gh/jasnell/node-skills/node-quic-dtls
last_updated: 2026-11-19T20:15:43.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [examples/dtls-loopback.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-quic-dtls/examples/dtls-loopback.mjs), [examples/quic-loopback.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-quic-dtls/examples/quic-loopback.mjs), [meta.json](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-quic-dtls/meta.json), [rules/dtls-api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-quic-dtls/rules/dtls-api.md), [rules/quic-api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-quic-dtls/rules/quic-api.md).
>
> If the user asked to install this Skill, run `npx skilld install jasnell/node-skills/node-quic-dtls`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/node-quic-dtls`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jasnell/node-skills/node-quic-dtls) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/node-quic-dtls`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/node-quic-dtls --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/node-quic-dtls --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# node:quic and node:dtls

| Feature | Versions | Stability | Flag |
| --- | --- | --- | --- |
| `node:quic` core (`connect`, `listen`, endpoint/session/stream) | v23.8.0 | 1.0 | `--experimental-quic` (flag added v25.0.0, v24.16.0) |
| QUIC `alpn`/`sni` options | v26.1.0, v24.16.0 | 1.0 | same |
| `session.opened`, `stream.writer`/`setBody`/async iteration, HTTP/3 | v26.2.0, v24.20.0 | 1.0 | same |
| `node:dtls` `listen`/`connect`, PSK, SNI | v26.9.0 | 1.1 | `--experimental-dtls` |
| `dtls.createSecureContext`, `session.session`/`reused`/`authorized` | v26.10.0 | 1.1 | same |

**Both are compile-time options too.** The official v24.19.0 and v26.13.0
binaries and a default main build don't include them. `require` then throws
`ERR_UNKNOWN_BUILTIN_MODULE` even with the flag. You need a build made with
`./configure --experimental-quic --experimental-dtls` **and** the runtime
flag. Check with `node -p process.config.variables.node_use_quic` (`node_use_dtls`).
DTLS is not on v24.

> **Experimental API.** Before relying on these details, run the
> `node-experimental-check` skill's probe (or `node --version` plus a
> feature-detect one-liner) and check the docs for *the installed
> version*: `https://nodejs.org/docs/<version>/api/<module>.html`.
> If the installed version disagrees with this skill, the installed
> version wins.

## Model

- QUIC: a `QuicEndpoint` (UDP socket) carries `QuicSession`s (TLS 1.3), which
  carry `QuicStream`s. Events are callback properties (`onstream`, `onerror`).
  `opened` and `closed` are promises.
- DTLS: a `DTLSEndpoint` carries `DTLSSession`s that exchange datagrams
  (`send`, `onmessage`).

## QUIC echo (verified on a QUIC build of main)

```js
const pem = new TextEncoder().encode(certPem);          // PEM *bytes*; keys = KeyObject
const ep = await quic.listen((s) => { s.onstream = async (st) => {
  st.setBody('echo:' + await text(st)); }; },            // for await (const chunks of st)
  { alpn: ['demo'], sni: { '*': { keys: [key], certs: [pem] } },
    endpoint: { address: '127.0.0.1:0' } });
const c = await quic.connect(ep.address, { alpn: 'demo', servername: 'localhost', ca: [pem] });
await c.opened;
const st = await c.createBidirectionalStream({ body: 'hello' });
```

## DTLS echo

```js
const srv = dtls.listen((s) => { s.onmessage = (d) => s.send(d); },
  { cert, key, host: '127.0.0.1', port: 0 });            // sync; port required
const c = dtls.connect('127.0.0.1', srv.address.port, { ca: cert, servername: 'localhost' });
await c.opened; c.send('ping');                          // send only after opened
```

## Pitfalls

- QUIC defaults to ALPN `'h3'`. Set `alpn` on both sides for a raw protocol.
  The server needs `sni` (use `'*'` as the fallback).
- QUIC `verifyPeer: 'auto'` rejects self-signed certs without `ca`.
  `'manual'` exposes `validationErrorCode` (a string).
- Read every QUIC stream to the end, or `Stream.dump()` it. A stream takes a
  `body` *or* the `writer`, not both.
- `dtls.connect` takes an IP literal (no DNS). `send` is at most 16384 B and
  throws before `opened`.
- A wrong DTLS PSK or no common cipher makes the handshake go silent. Set
  `handshakeTimeout` (default 60 s).
- Both need `--allow-net` under `--permission`.

## Don't

- Don't assume `node:quic`/`node:dtls` exist because the version is new enough.
  Check `process.config` and tell the user if a custom build is needed.
- Don't promise HTTP/3 `fetch()`. `node:quic` is low-level framing only.

## Reference

- [rules/quic-api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-quic-dtls/rules/quic-api.md): read for the QUIC endpoint/session/stream API, all options, stats, HTTP/3, datagrams, 0-RTT.
- [rules/dtls-api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-quic-dtls/rules/dtls-api.md): read for DTLS options, PSK, SNI, resumption, ticket keys, DoS limits, SRTP, stats.
