Registry / testing / responselike

responselike

JSON →
library4.0.2jsnpmunverified

Responselike provides a streamable object designed to mimic a Node.js HTTP response stream (`http.IncomingMessage`). This utility is primarily used for mocking HTTP responses in testing scenarios or for reformatting cached data to be consumed by code expecting a standard HTTP response. The current stable version is 4.0.2. The package is actively maintained by Sindre Sorhus, with releases typically occurring as needed for bug fixes or Node.js version updates, as seen with the recent v4.0.0 and v4.0.1/v4.0.2 updates. Its key differentiator is its focus on accurately replicating the streamable nature and properties of a native HTTP response, making it suitable for integrations where stream-based consumption is expected, unlike simpler object mocks.

npm install responselike
INSTALL
IMPORT
SIG · RESPONSELIKE
R
responselike
testingjavascriptv4.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Response
import Response from 'responselike';
const Response = require('responselike');
The package is pure ESM since v3.0.0, requiring `import` syntax. 'Response' is the default export.
ResponseOptions
import type { ResponseOptions } from 'responselike';
Type import for the constructor options object, useful for TypeScript users.

Demonstrates creating a mock HTTP response, accessing its properties, and piping its body as a stream.

import Response from 'responselike'; import { Writable } from 'stream'; class TestStream extends Writable { _write(chunk, encoding, callback) { console.log(chunk.toString()); callback(); } } const response = new Response({ statusCode: 200, headers: { 'content-type': 'text/plain', 'x-custom-header': 'value' }, body: Buffer.from('Hello, World! This is a mocked response body.'), url: 'https://example.com/api/data' }); console.log(`Status Code: ${response.statusCode}`); console.log(`URL: ${response.url}`); console.log('Headers:', response.headers); const testOutput = new TestStream(); console.log('\nStreaming body content:'); response.pipe(testOutput);
Debug
Known issues
breakingVersion 4.0.0 and newer require Node.js version 20 or higher.
fix
Upgrade your Node.js environment to version 20 or greater. If unable to upgrade, use `responselike@3.x` for Node.js 14+ or `responselike@2.x` for older Node.js versions.
affects: >=4.0.0
breakingVersion 3.0.0 introduced breaking changes, requiring Node.js 14 and transitioning the package to pure ESM. CommonJS `require()` is no longer supported.
fix
Migrate your codebase to use ESM `import` statements. Refer to Sindre Sorhus's 'pure ESM' gist for guidance on migrating projects. Ensure your `package.json` is configured correctly for ESM.
affects: >=3.0.0
breakingSince v3.0.0, the `Response` constructor now accepts a single `options` object instead of multiple positional arguments.
fix
Refactor calls from `new Response(statusCode, headers, body, url)` to `new Response({ statusCode, headers, body, url })`.
affects: >=3.0.0
gotchaWhen providing headers, keys will be automatically lowercased by the `Response` object to mimic standard HTTP header behavior.
fix
Be aware that accessing headers should use lowercase keys, e.g., `response.headers['content-type']` even if originally provided as `{'Content-Type': '...'}`.
affects: *
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to `require()` responselike in an ESM project, or attempting to `require()` a pure ESM package in a CommonJS context.
fix
Use `import Response from 'responselike';` instead of `const Response = require('responselike');`. Ensure your project is set up for ESM, potentially by adding `"type": "module"` to your `package.json`.
TypeError: Cannot read properties of undefined (reading 'pipe')
The `body` property passed to the `Response` constructor was not a `Buffer` or was missing, leading to an unstreamable object.
fix
Ensure the `body` option is explicitly set to a `Buffer.from('your content')` when creating a new `Response` instance.
TypeError: responselike_1.default is not a constructor
Incorrectly importing `Response` as a named export or attempting to use `new` on the module itself when it's a default export.
fix
Correct the import statement to `import Response from 'responselike';` (for ESM) or verify your CommonJS wrapper if using older Node.js versions.
Upgrade
Version history
4.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
responselike — npm install responselike · libregistry