# responselike

> A response-like object for mocking a Node.js HTTP response stream

Latest version **4.0.2** (published 2025-10-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install responselike
pnpm add responselike
yarn add responselike
bun add responselike
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.2 |
| Published | 2025-10-10 |
| First published | 2017-05-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 37 |
| Maintainers | sindresorhus |
| Keywords | http, https, response, mock, test, request, responselike |

## Links

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

## Dependencies (1)

- [lowercase-keys](https://npm.io/package/lowercase-keys.md) ^3.0.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 4.0.2 (latest) — 2025-10-10
- 4.0.1 — 2025-10-10
- 4.0.0 — 2025-10-10
- 3.0.0 — 2022-07-18
- 2.0.1 — 2022-07-18
- 2.0.0 — 2019-10-08
- 1.0.2 — 2017-08-17
- 1.0.1 — 2017-06-30
- 1.0.0 — 2017-06-21
- 0.2.0 — 2017-06-19
- 0.1.0 — 2017-05-04

## README

# responselike

> A response-like object for mocking a Node.js HTTP response stream

Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage). Useful for formatting cached responses so they can be consumed by code expecting a real response.

## Install

```sh
npm install responselike
```

## Usage

```js
import Response from 'responselike';

const response = new Response({
	statusCode: 200,
	headers: {
		foo: 'bar'
	},
	body: Buffer.from('Hi!'),
	url: 'https://example.com'
});

response.statusCode;
// 200

response.headers;
// {foo: 'bar'}

response.body;
// <Buffer 48 69 21>

response.url;
// 'https://example.com'

response.pipe(process.stdout);
// 'Hi!'
```

## API

### new Response(options?)

Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage).

#### options

Type: `object`

##### statusCode

Type: `number`

The HTTP response status code.

##### headers

Type: `object`

The HTTP headers. Keys will be automatically lowercased.

##### body

Type: `Buffer`

The response body. The Buffer contents will be streamable but is also exposed directly as `response.body`.

##### url

Type: `string`

The request URL string.

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