from2 is a convenience wrapper for Node.js `ReadableStream` (specifically, the `readable-stream` base class), designed to simplify the creation of readable streams while correctly handling backpressure. The current stable version is 2.3.0, published in 2016, indicating the project is likely abandoned or in long-term maintenance with no active development or planned release cadence. It differentiates itself by offering an API inspired by `from` and `through2`, providing `from2.obj` for object mode streams and `from2.ctor` for creating reusable stream constructors, which can improve performance for multiple similar streams. It aims to make stream creation more approachable than direct `ReadableStream` implementation.
npm install from2Verified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a basic readable stream using `from2` that emits chunks of a given string, handling backpressure appropriately, and then pipes it to standard output.
Be aware that the API, while stable in its current form, was once considered experimental. Thorough testing is recommended if relying on specific undocumented behaviors.
Evaluate modern stream implementations like Node.js's native `stream.Readable` or newer libraries that are actively maintained. Consider forking the project or implementing custom stream logic if specific `from2` behavior is critical and security/maintenance concerns are addressed internally.
Always use `const from = require('from2')` for Node.js applications. If you must use `from2` in an ESM context, consider a bundler like Webpack or Rollup, or use `import from2 from 'from2'` (for default export) followed by `from2.obj` or `from2.ctor`. However, the direct `import { obj } from 'from2'` will not work.Use CommonJS `require` for `from2` and access properties directly: `const from = require('from2'); const myStream = from.obj(...)`.Ensure your project or build system correctly handles `from2` as a CommonJS module. If you are in an ESM context and cannot avoid `from2`, use dynamic `import('from2')` and then access the default export's properties, e.g., `(await import('from2')).default.obj(...)`. Note that `from2` itself is CJS, so `require` should generally work.