http2-wrapper is a Node.js library that provides an HTTP/2 client using an API familiar to users of Node's built-in `https` module. It allows existing codebases that rely on the HTTP/1 API to transparently support HTTP/2 without extensive rewrites. The current stable version is 2.2.1, with releases occurring as needed for bug fixes and minor improvements, typically every few weeks as seen in recent changelogs. A key differentiator is its ability to bridge HTTP/1-style agents with native HTTP/2 streams, enabling HTTP/2 support in modules designed for HTTP/1. While the maintainer recommends using the native `http2` module directly for new projects, `http2-wrapper` excels as a compatibility layer or when custom HTTP/2 agents are needed. It ships with TypeScript types, facilitating safer development in TypeScript environments.
npm install http2-wrapperVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to make a basic HTTP/2 POST request using the `request` API, similar to Node.js's native `https.request`.
Update request options, replacing `session` with `tlsSession` (e.g., `{ tlsSession: yourTlsSession }`).To set a session timeout, create an `http2.Agent` instance with the desired `timeout` and pass it in the request options: `new http2.Agent({ timeout: 5000 })`.Evaluate if direct usage of Node.js `http2` module is more suitable for new projects or when maximum control over HTTP/2 protocol specifics is desired.
Verify server ALPN configuration and ensure the `protocol` option in your request (e.g., `protocol: 'https:'`) aligns with the expected negotiation. TLS handshake failures or protocol errors often stem from ALPN mismatches.
For CommonJS, use `const http2 = require('http2-wrapper');`. For ESM, use `import * as http2 from 'http2-wrapper';` or specifically `import { request } from 'http2-wrapper';`.Change the `protocol` option to `'https:'` for ALPN negotiation, or ensure the server explicitly supports h2c and configure the client accordingly if HTTP/2 over plain HTTP is intended.
For development or trusted internal environments, you can bypass validation with `process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'` (use with extreme caution!). For production, provide custom CA certificates via `options.ca` or ensure proper certificate chain.
No dependency data recorded yet.