Streams

Readable.toWeb()

Adapts a Node readable to a Web ReadableStream. The resulting reader locks the Web stream until released; do not independently consume both views. Select compatible chunk types and buffering strategy when bridging APIs. Tested on Node.js 22.16.0. The Node 22.16.0 documentation classifies this adapter as experimental. Example output (one line per entry): ["one-two"].

Formal Syntax & Structure

nodejs syntaxnodejs
Readable.toWeb(streamReadable[, options])

Parameters & Attributes

NameTypeDescription
streamReadableReadableNode source.
optionsobjectOptional strategy settings.

Return Value

ReadableStream

Web-stream representation.

Working Example

Example Snippetnodejs
import { Readable } from 'node:stream';const reader = Readable.toWeb(Readable.from(['one', 'two'])).getReader();try {    const values = [];    while (true) {        const { done, value } = await reader.read();        if (done)            break;        values.push(value);    }    console.log(values.join('-'));}finally {    reader.releaseLock();}
Node.js Reference