{"id":14760,"library":"node-web-stream-adapters","title":"Node.js Web Stream Adapters","description":"This package provides utilities to convert Node.js `Readable` and `Writable` streams into Web `ReadableStream` and `WritableStream` objects, and vice-versa. It aims to bridge the gap between Node.js's native stream API and the WHATWG Web Streams API, offering stable conversion functions. This is particularly useful because Node.js's own `Readable.toWeb`, `Writable.toWeb`, `Readable.fromWeb`, and `Writable.fromWeb` methods are marked as experimental as of Node.js version 22. The package is currently at version 0.2.1, indicating an early development stage, though it addresses a stable need. It is likely maintained as needed to keep pace with Node.js and Web Streams API evolutions. Key differentiators include providing a non-experimental, stable API surface for stream conversion.","status":"active","version":"0.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/bstefanescu/node-readable-stream","tags":["javascript","ReadableStream","WritableStream","stream","Readable","Writable","node","web","adapter","typescript"],"install":[{"cmd":"npm install node-web-stream-adapters","lang":"bash","label":"npm"},{"cmd":"yarn add node-web-stream-adapters","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-web-stream-adapters","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This library ships as an ES module. While `require()` might work in some Node.js configurations, `import` is the officially supported and recommended way. The README shows `from 'node-readable-stream'`, which is a different package name and will result in errors if `node-web-stream-adapters` is installed.","wrong":"const { toReadableStream } = require('node-web-stream-adapters');","symbol":"toReadableStream","correct":"import { toReadableStream } from 'node-web-stream-adapters';"},{"note":"This helper function converts an existing Node.js Readable stream into a Web ReadableStream. Ensure you import from the correct package name, `node-web-stream-adapters`, not `node-readable-stream`.","symbol":"createReadableStreamFromReadable","correct":"import { createReadableStreamFromReadable } from 'node-web-stream-adapters';"},{"note":"This utility simplifies creating a Web ReadableStream directly from a Buffer. As with other exports, use the `node-web-stream-adapters` package name in your import statement.","symbol":"createReadableStreamFromBuffer","correct":"import { createReadableStreamFromBuffer } from 'node-web-stream-adapters';"}],"quickstart":{"code":"import fs from \"fs/promises\";\nimport { createReadableStreamFromBuffer } from \"node-web-stream-adapters\";\n\nasync function processFileAsStream() {\n  try {\n    const filePath = 'some-file.txt';\n    // Assume 'some-file.txt' exists and has content.\n    // In a real scenario, you might read a large file or network response.\n    const buffer = await fs.readFile(filePath);\n    const webStream = createReadableStreamFromBuffer(buffer);\n\n    console.log('Created Web ReadableStream from buffer.');\n\n    // Example: Consume the web stream (e.g., pipe to another writable stream or process chunks)\n    const reader = webStream.getReader();\n    while (true) {\n      const { done, value } = await reader.read();\n      if (done) {\n        console.log('Stream finished.');\n        break;\n      }\n      console.log('Received chunk:', new TextDecoder().decode(value));\n    }\n  } catch (error) {\n    console.error('Error processing stream:', error);\n  }\n}\n\n// Create a dummy file for the example to run\nasync function setupDummyFile() {\n  const content = 'Hello, Web Streams!\\nThis is a test file.';\n  await fs.writeFile('some-file.txt', content);\n  console.log('Dummy file created: some-file.txt');\n  await processFileAsStream();\n}\n\nsetupDummyFile();","lang":"typescript","description":"This example demonstrates how to convert a Node.js Buffer into a Web ReadableStream using `createReadableStreamFromBuffer` and then consume it."},"warnings":[{"fix":"Always use `import { ... } from 'node-web-stream-adapters'` in your code if you installed the `node-web-stream-adapters` package. Verify the exact package name on npm if unsure, as the README might be outdated or refer to a different package/alias.","message":"The documentation (README) and the provided GitHub URL (`https://github.com/bstefanescu/node-readable-stream`) explicitly refer to `node-readable-stream` as the package name for installation and imports. However, the npm metadata provided specifies `node-web-stream-adapters`. This discrepancy is a critical point of confusion and will lead to `ERR_MODULE_NOT_FOUND` if the README's instructions are followed with the `node-web-stream-adapters` package installed.","severity":"breaking","affected_versions":">=0.2.1"},{"fix":"Monitor Node.js release notes for updates on the Web Streams API and its native integration. For now, using this library provides a robust solution, but be prepared for potential future migration paths if Node.js stabilizes its own converters.","message":"Node.js core's native `Readable.toWeb`, `Writable.toWeb`, `Readable.fromWeb`, and `Writable.fromWeb` methods are currently experimental (as of Node.js 22). While this library provides stable alternatives, be aware that future Node.js versions might stabilize their native implementations, potentially deprecating or superseding this library's approach. This package aims to offer stability where native Node.js methods are still in flux.","severity":"gotcha","affected_versions":">=0.2.1"},{"fix":"Pin exact versions (e.g., `\"node-web-stream-adapters\": \"0.2.1\"`) or use caret ranges (`\"^0.2.1\"`) with caution, thoroughly reviewing changelogs for any updates. Regular testing is recommended when upgrading minor or patch versions.","message":"As a relatively new package (version 0.2.1), its API surface might undergo breaking changes in minor or patch releases, even though semantic versioning is typically followed. Low version numbers often indicate that the API is still finding its final form.","severity":"gotcha","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statements to `import { ... } from 'node-web-stream-adapters';`.","cause":"You are trying to import from 'node-readable-stream' as shown in the README, but you have installed 'node-web-stream-adapters'.","error":"ERR_MODULE_NOT_FOUND: Cannot find module 'node-readable-stream' from '/path/to/your/file.js'"},{"fix":"Ensure you are using ES module `import` syntax: `import { toReadableStream } from 'node-web-stream-adapters';` and check that `type: \"module\"` is set in your `package.json` if running in Node.js, or use a bundler that handles ESM correctly.","cause":"This error typically occurs when trying to use CommonJS `require()` syntax (e.g., `const { toReadableStream } = require('node-web-stream-adapters');`) with an ES module-only package, or when incorrectly importing a named export as a default or vice-versa.","error":"TypeError: (0, _nodeWebStreamAdapters.toReadableStream) is not a function"}],"ecosystem":"npm"}