Registry / http-networking / http2-express

http2-express

JSON →
library1.1.0jsnpmunverified

http2-express integrates HTTP/2 protocol support into Express.js applications. The current stable version, 1.1.0, adds explicit support for Express 5 while maintaining backward compatibility with Express 4. Its release cadence is responsive to major Express and Node.js version updates. A key differentiator is its direct compatibility with the now-deprecated `http2-express-bridge` package, allowing for a straightforward migration by just changing the import name. Unlike its predecessor, http2-express intentionally removes support for HTTP/2 Server Push, aligning with current browser and client behavior where Server Push is largely deprecated due to observed limited or negative performance impacts. The library supports both secure (HTTPS/2) and insecure (h2c) HTTP/2 connections and provides options for backward compatibility with HTTP/1.1 clients.

npm install http2-express
INSTALL
IMPORT
SIG · HTTP2-EXPRESS
H
http2-express
http-networkingjavascriptv1.1.0
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.

http2Express
import http2Express from 'http2-express';
import { http2Express } from 'http2-express';
The package exports a single function as its default, which is used to wrap an Express application instance. CommonJS `const http2Express = require('http2-express');` also works.
express
import express from 'express';
const express = require('express');
Express is a peer dependency and must be imported separately. The `http2-express` function then takes the Express app instance. The wrong example refers to CommonJS usage in an ESM context without proper loader configuration.
http2
import * as http2 from 'node:http2';
import http2 from 'node:http2';
The native Node.js HTTP/2 module is essential for creating the server and is typically imported as a namespace object (`* as`). Using `node:` prefix is best practice for built-in modules in modern Node.js ESM.

This example demonstrates setting up a basic HTTP/2 Express server with TLS (HTTPS/2) support, serving a 'Hello World' message. It highlights how to wrap an Express app, configure certificates, and listen for connections.

import express from 'express'; import * as http2 from 'node:http2'; import http2Express from 'http2-express'; import fs from 'node:fs'; const app = http2Express(express); app.get('/', (req, res) => { res.send('Hello World from HTTP/2!'); }); const options = { key: fs.readFileSync(process.env.HTTP2_KEY_PATH ?? 'path/to/your/certificate.key'), cert: fs.readFileSync(process.env.HTTP2_CERT_PATH ?? 'path/to/your/certificate.crt'), passphrase: process.env.HTTP2_CERT_PASSPHRASE ?? 'your_certificate_passphrase', allowHTTP1: false }; const server = http2.createSecureServer(options, app); server.listen(44320, () => { console.info('HTTP/2 server listening on https://localhost:44320...'); });
Debug
Known issues
breakingThis package explicitly removes support for HTTP/2 Server Push, which was present in its predecessor `http2-express-bridge`. Most major browsers and HTTP/2 clients have deprecated or disabled Server Push due to limited performance gains.
fix
Review and remove any application logic that relies on HTTP/2 Server Push. Re-evaluate asset delivery strategies using standard HTTP/2 features or preloading via Link headers.
affects: >=1.0.0
gotchaThe package's `package.json` specifies Node.js version `>= 20.0.0` in its 'engines' field, while the README recommends `>= 19`. Running on Node.js versions older than 20.0.0 may lead to unexpected behavior or missing features.
fix
Ensure your Node.js environment is version 20.0.0 or higher for full compatibility and stability.
affects: <20.0.0
gotchaSetting `allowHTTP1: false` in the `http2.createSecureServer` options will prevent HTTP/1.1 clients from connecting to your server, resulting in connection errors for older browsers or clients that do not support HTTP/2.
fix
If backward compatibility with HTTP/1.1 clients is required, set `allowHTTP1: true` in the server options. This allows the server to negotiate between HTTP/1.1 and HTTP/2 protocols.
affects: >=1.0.0
gotchaWhile `http2-express` is designed as a drop-in replacement for `http2-express-bridge`, applications relying on specific internal behaviors or undocumented features of the old bridge might encounter subtle issues beyond the removal of Server Push.
fix
Perform thorough regression testing after migrating from `http2-express-bridge` to ensure all functionalities behave as expected, especially if your application had complex HTTP/2 interactions.
affects: >=1.0.0
gotchaVersion 1.0.0 of `http2-express` had an issue with h2c (running HTTP/2 without TLS). While fixed in 1.0.1, users on the initial release might encounter problems when creating non-HTTPS HTTP/2 servers.
fix
Upgrade to `http2-express@^1.0.1` or a newer version to ensure proper functionality for h2c (non-HTTPS HTTP/2) servers.
affects: =1.0.0
Errors
Common errors & fixes
ERR_HTTP2_INCOMPATIBLE_SERVER
An HTTP/1.1 client attempted to connect to an HTTP/2 server configured with `allowHTTP1: false`.
fix
Configure the HTTP/2 server with `allowHTTP1: true` in the options object if HTTP/1.1 client compatibility is desired. Otherwise, ensure all connecting clients support HTTP/2.
Error: EISDIR: illegal operation on a directory, read
The `fs.readFileSync` calls for `key` or `cert` were provided with paths to directories instead of the actual certificate and key files.
fix
Verify that `options.key` and `options.cert` point to the full file paths of your TLS certificate key and certificate files, respectively, not just their containing directories.
TypeError: res.push is not a function
Attempting to use `res.push()` for Server Push, a feature removed in `http2-express`.
fix
Remove all calls to `res.push()` and refactor the application to use alternative methods for asset delivery, such as Link preload headers, as HTTP/2 Server Push is no longer supported by this package or widely by browsers.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
expressrequiredThis package wraps an Express application to provide HTTP/2 capabilities, making Express a core conceptual dependency.
Agent activity
8 hits · last 30 days
node
8
Resources
http2-express — npm install http2-express · libregistry