{"id":17270,"library":"http2-express","title":"HTTP/2 Support for Express","description":"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.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/markjovis/http2-express","tags":["javascript","express","http2","https","push","support","compatibility","api","server"],"install":[{"cmd":"npm install http2-express","lang":"bash","label":"npm"},{"cmd":"yarn add http2-express","lang":"bash","label":"yarn"},{"cmd":"pnpm add http2-express","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package wraps an Express application to provide HTTP/2 capabilities, making Express a core conceptual dependency.","package":"express","optional":false}],"imports":[{"note":"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.","wrong":"import { http2Express } from 'http2-express';","symbol":"http2Express","correct":"import http2Express from 'http2-express';"},{"note":"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.","wrong":"const express = require('express');","symbol":"express","correct":"import express from 'express';"},{"note":"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.","wrong":"import http2 from 'node:http2';","symbol":"http2","correct":"import * as http2 from 'node:http2';"}],"quickstart":{"code":"import express from 'express';\nimport * as http2 from 'node:http2';\nimport http2Express from 'http2-express';\nimport fs from 'node:fs';\n\nconst app = http2Express(express);\n\napp.get('/', (req, res) => {\n  res.send('Hello World from HTTP/2!');\n});\n\nconst options = {\n  key: fs.readFileSync(process.env.HTTP2_KEY_PATH ?? 'path/to/your/certificate.key'),\n  cert: fs.readFileSync(process.env.HTTP2_CERT_PATH ?? 'path/to/your/certificate.crt'),\n  passphrase: process.env.HTTP2_CERT_PASSPHRASE ?? 'your_certificate_passphrase',\n  allowHTTP1: false\n};\n\nconst server = http2.createSecureServer(options, app);\n\nserver.listen(44320, () => {\n  console.info('HTTP/2 server listening on https://localhost:44320...');\n});","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure your Node.js environment is version 20.0.0 or higher for full compatibility and stability.","message":"The 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.","severity":"gotcha","affected_versions":"<20.0.0"},{"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.","message":"Setting `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"While `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to `http2-express@^1.0.1` or a newer version to ensure proper functionality for h2c (non-HTTPS HTTP/2) servers.","message":"Version 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.","severity":"gotcha","affected_versions":"=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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.","cause":"An HTTP/1.1 client attempted to connect to an HTTP/2 server configured with `allowHTTP1: false`.","error":"ERR_HTTP2_INCOMPATIBLE_SERVER"},{"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.","cause":"The `fs.readFileSync` calls for `key` or `cert` were provided with paths to directories instead of the actual certificate and key files.","error":"Error: EISDIR: illegal operation on a directory, read"},{"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.","cause":"Attempting to use `res.push()` for Server Push, a feature removed in `http2-express`.","error":"TypeError: res.push is not a function"}],"ecosystem":"npm","meta_description":null}