# mimic-response

> Mimic a Node.js HTTP response stream

Latest version **4.0.0** (published 2021-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install mimic-response
pnpm add mimic-response
yarn add mimic-response
bun add mimic-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 | 4.0.0 |
| Published | 2021-08-11 |
| First published | 2017-06-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 61 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | mimic, response, stream, http, https, request, get, core |

## Links

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

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2021-08-11
- 3.1.0 — 2020-05-14
- 3.0.0 — 2020-05-13
- 2.1.0 — 2020-02-17
- 2.0.0 — 2019-01-20
- 1.0.1 — 2018-07-11
- 1.0.0 — 2017-06-02

## README

# mimic-response

> Mimic a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage)

## Install

```
$ npm install mimic-response
```

## Usage

```js
import {PassThrough as PassThroughStream} from 'node:stream';
import mimicResponse from 'mimic-response';

const responseStream = getHttpResponseStream();
const myStream = new PassThroughStream();

mimicResponse(responseStream, myStream);

console.log(myStream.statusCode);
//=> 200
```

## API

### mimicResponse(from, to)

**Note #1:** The `from.destroy(error)` function is not proxied. You have to call it manually:

```js
import {PassThrough as PassThroughStream} from 'node:stream';
import mimicResponse from 'mimic-response';

const responseStream = getHttpResponseStream();

const myStream = new PassThroughStream({
	destroy(error, callback) {
		responseStream.destroy();

		callback(error);
	}
});

myStream.destroy();
```

Please note that `myStream` and `responseStream` never throw. The error is passed to the request instead.

#### from

Type: `Stream`

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

#### to

Type: `Stream`

Any stream.

## Related

- [mimic-fn](https://github.com/sindresorhus/mimic-fn) - Make a function mimic another one
- [clone-response](https://github.com/lukechilds/clone-response) - Clone a Node.js response stream

---

<div align="center">
	<b>
		<a href="https://tidelift.com/subscription/pkg/npm-mimic-response?utm_source=npm-mimic-response&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
	</b>
	<br>
	<sub>
		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
	</sub>
</div>

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