http2-client is a Node.js library designed to provide a transparent, drop-in replacement for Node's native `http` and `https` modules. It allows applications to make requests that automatically negotiate between HTTP/1.1 and HTTP/2 protocols using ALPN, without requiring changes to the existing `http.request` or `http.get` interfaces. This is particularly useful for integrating HTTP/2 capabilities into older modules or applications that are tightly coupled to the HTTP/1.1 API. The library manages connection pooling for both protocols, ensuring efficient resource utilization. The current stable version is 1.3.5. Based on the provided release history (v1.3.2, v1.3.3), the package appears to have an infrequent release cadence, suggesting a maintenance rather than actively developed status. Key differentiators include its adherence to the standard Node.js `http` module API and automatic protocol detection.
npm install http2-clientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `http2-client`'s `request` function to make transparent requests to both HTTP/1.1 and HTTP/2 servers using the same API as Node's native `http` module. It prints the URL, status code, and HTTP version for each response.
Ensure your project is configured for CommonJS, or use dynamic `import()` if absolutely necessary within an ESM context, though this is not officially supported by the library.
If HTTP/2 server push is a requirement, consider using Node.js's native `http2` module directly or a different HTTP client library that offers full HTTP/2 feature parity.
Evaluate modern alternatives like `undici` or Node.js's built-in `fetch` API, which offer robust HTTP/2 support, especially for newer projects, if active development and broader feature sets are crucial.
Ensure your Node.js version (typically >=8.8.1 for `http2` module availability) supports HTTP/2 if you intend to use it. Monitor `res.httpVersion` in your callbacks to confirm the protocol used.
First, ensure `npm install http2-client` was successful. If using a bundler, verify CommonJS modules are correctly handled. If running in an ES module context, consider if `require()` is appropriate or if a different library designed for ESM is needed.
Remove explicit `protocol` options if you want the library to automatically handle protocol detection based on the URL. Ensure your Node.js version supports ALPN for HTTPS/2 negotiation (typically Node.js 8.8.1+).
No dependency data recorded yet.