The `clone-response` package provides a utility function to duplicate a Node.js HTTP response stream, effectively creating an unconsumed copy. This is particularly useful in scenarios where a response stream needs to be processed in multiple asynchronous contexts or passed to different consumers without fully draining the original stream for all parties. The package ensures that all properties and methods from the original `IncomingMessage` are copied to the new stream, creating a complete duplicate. As of version 2.0.0, it is a pure ESM module and requires Node.js 14 or higher. The package maintains a stable release cadence, primarily updating for Node.js compatibility and modern JavaScript module standards. Its core differentiator is the reliable duplication of a response stream's state and data, enabling flexible handling of HTTP responses without complex stream buffering or re-fetching.
npm install clone-responseVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to clone an HTTP response stream immediately after receiving it, allowing the original to be piped to `process.stdout` while the cloned stream remains available for later asynchronous consumption.
Migrate your project to ESM using `import` statements or use an older version of the package if CommonJS is strictly required. Ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions.
Upgrade your Node.js runtime to version 14.16 or newer. If unable to upgrade, you must use `clone-response` version 1.x.x.
Be mindful of stream consumption order. Clone the stream as early as possible. If you need to use the original stream in an async context, ensure you create a clone *before* any operations that might consume it asynchronously.
Change your import statement from `const cloneResponse = require('clone-response');` to `import cloneResponse from 'clone-response';`. Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).Use the correct default import syntax: `import cloneResponse from 'clone-response';`.
Update `const http = require('http');` to `import http from 'node:http';` to consistently use ESM import syntax with `node:` protocol for built-in modules.No dependency data recorded yet.