# clone-response

> Clone a Node.js HTTP response stream

Latest version **2.0.0** (published 2022-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install clone-response
pnpm add clone-response
yarn add clone-response
bun add clone-response
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-07-17 |
| First published | 2017-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=14.16 |
| Dependencies | 1 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Luke Childs |
| Maintainers | sindresorhus, lukechilds |
| Keywords | clone, response, duplicate, copy, http, stream |

## Links

- npm: https://www.npmjs.com/package/clone-response
- Repository: https://github.com/sindresorhus/clone-response
- Homepage: https://github.com/sindresorhus/clone-response#readme
- Issues: https://github.com/sindresorhus/clone-response/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/clone-response

## Dependencies (1)

- [mimic-response](https://npm.io/package/mimic-response.md) ^4.0.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2022-07-17
- 1.0.3 — 2022-07-17
- 1.0.2 — 2017-08-17
- 1.0.1 — 2017-06-30
- 1.0.0 — 2017-06-16
- 0.2.2 — 2017-06-03
- 0.2.1 — 2017-06-03
- 0.2.0 — 2017-06-02
- 0.1.1 — 2017-06-02
- 0.1.0 — 2017-06-02
- 0.0.0 — 2017-06-01

## README

# clone-response

> Clone a Node.js HTTP response stream

Returns a new stream and copies over all properties and methods from the original response giving you a complete duplicate.

This is useful in situations where you need to consume the response stream but also want to pass an unconsumed stream somewhere else to be consumed later.

## Install

```sh
npm install clone-response
```

## Usage

```js
import http from 'node:http';
import cloneResponse from 'clone-response';

http.get('http://example.com', response => {
	const clonedResponse = cloneResponse(response);
	response.pipe(process.stdout);

	setImmediate(() => {
		// The response stream has already been consumed by the time this executes,
		// however the cloned response stream is still available.
		doSomethingWithResponse(clonedResponse);
	});
});
```

Please bear in mind that the process of cloning a stream consumes it. However, you can consume a stream multiple times in the same tick, therefore allowing you to create multiple clones. For example:

```js
const clone1 = cloneResponse(response);
const clone2 = cloneResponse(response);
// The response can still be consumed in this tick but cannot be consumed if passed
// into any async callbacks. clone1 and clone2 can be passed around and be
// consumed in the future.
```

## API

### cloneResponse(response)

Returns a clone of the passed in response stream.

#### response

Type: `Stream`

A [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage) to clone.

---
_Source: https://npm.io/package/clone-response · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
