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-expressVerified import paths — ran on the pinned version, not inferred.
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.
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.
Ensure your Node.js environment is version 20.0.0 or higher for full compatibility and stability.
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.
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.
Upgrade to `http2-express@^1.0.1` or a newer version to ensure proper functionality for h2c (non-HTTPS HTTP/2) servers.
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.
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.
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.