Web Streams

ReadableStream.tee()

Creates two branches. A slow branch can accumulate queued chunks, so do not use tee as an unlimited production fan-out. Tested on Node.js 22.16.0. Example output (one line per entry): ["x,x"].

Formal Syntax & Structure

nodejs syntaxnodejs
stream.tee()

Return Value

ReadableStream[]

Two branches.

Working Example

Example Snippetnodejs
const s = new ReadableStream({ start(c) { c.enqueue('x'); c.close(); } });const [a, b] = s.tee();const consume = async (stream) => { const r = stream.getReader(); try {    return (await r.read()).value;}finally {    r.releaseLock();} };console.log((await Promise.all([consume(a), consume(b)])).join(','));
Node.js Reference