Intermediate LevelNode JS
What is the difference between native Node.js Streams (node:stream) and standard WHATWG Web Streams (ReadableStream)?
❓ Interview Prompt: WHATWG Web Streams (ReadableStream, WritableStream) are browser-compatible standard streams used in fetch and Cloudflare Workers. Node 18+ supports both and provides stream.toWeb() / stream.fromWeb() converters.
Node.js supports two stream implementations:
1
Native Node Streams ('node:stream'): Legacy high-performance Node-specific streams ('fs.createReadStream').
2
WHATWG Web Streams ('ReadableStream', 'WritableStream'): Standard browser-compatible streams used in 'fetch()', Deno, and Cloudflare Workers.
•
Convert between formats via 'Stream.toWeb(nodeStream)' and 'Stream.fromWeb(webStream)'!
Code Implementation Example
javascript
import { Readable } from 'node:stream';
const nodeStream = Readable.from(['Hello ', 'Web ', 'Streams!']);
// Convert native Node stream to WHATWG Web Stream!
const webStream = Readable.toWeb(nodeStream);
console.log('Is Web Stream:', webStream instanceof ReadableStream);💡Converting native Node.js streams to standard WHATWG Web Streams.
🎯 Interview Key Takeaway
Use WHATWG Web Streams for cross-platform code targeting browsers, Cloudflare Workers, and Node.js.
#Web Streams#ReadableStream#WHATWG#Intermediate
Back to all Node JS Questions→