The `mimic-response` library is a utility designed to replicate properties and events from a Node.js `http.IncomingMessage` (an HTTP response stream) onto any generic Node.js stream. This is particularly useful in scenarios like proxying or transforming HTTP responses where the downstream stream needs to inherit metadata such as `statusCode`, `statusMessage`, and `headers` without copying the actual data payload. The current stable version is `4.0.0`. Historically, new major versions have been released roughly annually, typically coinciding with updated Node.js LTS requirements and ecosystem shifts like the move to pure ESM. Its key differentiator lies in its specific focus on mirroring *response stream properties* rather than content, providing a lightweight way to maintain HTTP context across stream transformations. It stands apart from related tools like `mimic-fn` (for functions) or broader stream cloning utilities by targeting the specific metadata of an HTTP response.
npm install mimic-responseVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `mimicResponse` to transfer HTTP response metadata like `statusCode` and `headers` from a source stream (simulated `IncomingMessage`) to a target `PassThroughStream`, and also illustrates the important `destroy` proxying caveat.
Migrate your project to use ES modules by adding `"type": "module"` to your `package.json` and using `import` statements, or ensure your consuming code is already an ES module. For existing CommonJS projects that cannot migrate, use `await import('mimic-response')` for dynamic loading.Ensure your Node.js environment meets the minimum version requirement. Upgrade Node.js if necessary.
Ensure your Node.js environment is at least version 10.x. Upgrade Node.js if necessary, or downgrade `mimic-response` to a v2.x version if strict Node.js 8.x compatibility is required.
Ensure your Node.js environment is at least version 8.x. Upgrade Node.js if necessary, or use `mimic-response` v1.x for older Node.js compatibility.
When creating your target stream, provide a `destroy` method in its constructor options that explicitly calls the `destroy` method of the `from` stream, as shown in the package's API documentation example.
Refactor your consuming code to use `import` syntax within an ES module (by adding `"type": "module"` to `package.json` or using `.mjs` files), or use dynamic `import` like `const mimicResponse = (await import('mimic-response')).default;`.Add `"type": "module"` to your `package.json` file, or rename your file to have a `.mjs` extension. Ensure your Node.js version is compatible (Node.js 12.20.0 or higher for v4.x).
Use the correct default import syntax: `import mimicResponse from 'mimic-response';`.
Implement a `destroy` method in the constructor options of your target stream (e.g., `new PassThroughStream({ destroy(error, callback) { /* ... */ } })`) that also calls `from.destroy(error)` if propagation is desired.No dependency data recorded yet.