Replacements for readable-stream
readable-stream
mirrors Node’s core streams and works in browsers. In most cases, prefer native options.
Node.js (since v0.9.4)
Use the built-in stream
module (Node Streams docs).
ts
import { Duplex, Readable, Transform, Writable } from 'readable-stream'
import { Duplex, Readable, Transform, Writable } from 'node:stream'
Streams API (Browsers and Node.js 16.5.0+)
Use the Web Streams API (MDN) in browsers and modern Node. It’s global in Node 18+ (Node Web Streams docs); on 16.5–17.x import from stream/web
(details). Interop with Node streams is available via Readable.toWeb and Writable.fromWeb.
Example: convert a Web ReadableStream (from fetch) to a Node stream and pipe it to a file.
ts
import { Readable } from 'node:stream'
import { pipeline } from 'node:stream/promises'
import { createWriteStream } from 'node:fs'
const res = await fetch('https://example.com/data.txt') // Web ReadableStream
const nodeReadable = Readable.fromWeb(res.body)
await pipeline(nodeReadable, createWriteStream('data.txt'))