Streaming HTTP Requests (Substack's hyperquest)
raw JSON →Hyperquest is a lightweight, streaming HTTP client for Node.js, last updated to version 2.1.3 approximately eight years ago. It was created by Substack to address fundamental shortcomings in Node.js's native `http` module prior to version 0.12, specifically concerning default idle timeouts (2 minutes) and a restrictive connection pool limit (5 requests). These defaults often led to applications hanging or experiencing unexpected behavior when making multiple concurrent HTTP requests. Hyperquest bypassed these internal Node.js annoyances by treating HTTP requests purely as streaming transports, removing pooling and extending default timeouts significantly. While it offered a streamlined, 'request'-like API, it was designed for raw streaming without buffering or automatic JSON parsing. Given that its core purpose was to mitigate issues resolved in much older Node.js versions (specifically, Node.js 0.12 and later fixed many of these `http` module defaults), the package is now considered abandoned and not suitable for modern Node.js development.
Common errors
error ERR_REQUIRE_ESM: require() of ES Module ... from ... not supported. ↓
hyperquest is CommonJS, if you are in an ESM file, you must use import { createRequire } from 'module'; const require = createRequire(import.meta.url); const hyperquest = require('hyperquest');. However, consider migrating to a modern, actively maintained HTTP client with native ESM support. error TypeError: Cannot read properties of undefined (reading 'pipe') ↓
hyperquest() function is called with a well-formed URL string. For example: hyperquest('http://example.com/api'). Warnings
breaking The primary issues `hyperquest` was designed to solve (Node.js's default 2-minute idle timeout and 5-connection pooling limit in `http.request`) were largely addressed in Node.js 0.12 and subsequent versions. Using `hyperquest` in modern Node.js (v4.x+) offers little benefit and may introduce compatibility issues or unexpected behavior due to its outdated approach to HTTP streaming. ↓
deprecated The `hyperquest` package is effectively abandoned, with its last npm publication over eight years ago (v2.1.3 in January 2018). It is not maintained, does not receive security updates, and is not compatible with modern Node.js module systems (ESM). ↓
gotcha `hyperquest` is a CommonJS-only package. Attempting to `import hyperquest from 'hyperquest'` in an ESM module context will result in a runtime error. ↓
gotcha `hyperquest` provides a raw streaming interface, unlike higher-level libraries such as `request` or `axios` which automatically buffer responses or parse JSON. Users must manually handle stream events (`data`, `end`, `error`) and process chunks. ↓
Install
npm install hyperquest yarn add hyperquest pnpm add hyperquest Imports
- hyperquest wrong
import hyperquest from 'hyperquest';correctconst hyperquest = require('hyperquest');
Quickstart
const hyperquest = require('hyperquest');
const http = require('http');
// Create a simple HTTP server to test against
const server = http.createServer((req, res) => {
console.log(`Server received request for: ${req.url}`);
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello from hyperquest server!');
});
server.listen(8000, () => {
console.log('Server listening on http://localhost:8000');
// Make a streaming GET request using hyperquest
const reqStream = hyperquest('http://localhost:8000');
reqStream.on('data', (chunk) => {
process.stdout.write('Client received: ' + chunk.toString());
});
reqStream.on('end', () => {
console.log('\nClient finished receiving data.');
server.close(); // Close the server after the request is done
});
reqStream.on('error', (err) => {
console.error('Hyperquest error:', err);
server.close();
});
});