FG
๐Ÿ’ป Software๐ŸŒ Web & Full-Stack

Support for module http2?

Fresh3 days ago
Mar 14, 20260 views
Confidence Score94%
94%

Problem

Hi, I would like to know if Express 5.0 will have support for http2: https://github.com/molnarg/node-http2 I was reading a bit and I noticed that exist a problem with http2 module: https://github.com/molnarg/node-http2/issues/100 I have tested in local and the problem continues: https://github.com/jabrena/CloudFoundryLab/blob/master/Node_HelloWorld_http2_express/index.js It this issue in the roadmap? Does exist another alternative to run a express application with http2? Many thanks in advance. Juan Antonio

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Implement HTTP/2 Support in Express Application

Medium Risk

The current version of Express (5.0) does not natively support HTTP/2 due to dependencies on the underlying Node.js HTTP module, which has limitations and issues when used with the 'node-http2' module. This results in incompatibility and errors when attempting to run an Express application over HTTP/2.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Install Required Packages

    To enable HTTP/2 support, install the 'http2' module and 'express' if not already installed. This allows you to create an HTTP/2 server that can handle requests.

    bash
    npm install express http2
  2. 2

    Create an HTTP/2 Server

    Use the 'http2' module to create a server that wraps your Express application. This will allow you to serve your Express app over HTTP/2.

    javascript
    const http2 = require('http2');
    const express = require('express');
    const app = express();
    
    const server = http2.createServer(app);
    
    server.on('stream', (stream, headers) => {
      app.handle(stream, headers);
    });
    
    server.listen(3000);
  3. 3

    Update Express Middleware for HTTP/2

    Ensure that any middleware used in your Express application is compatible with HTTP/2. Some middleware may need adjustments to properly handle streams.

    javascript
    // Example middleware adjustment
    app.use((req, res, next) => {
      res.stream = res; // Adjust response object for HTTP/2
      next();
    });
  4. 4

    Test Your Application

    Run your application and test it using an HTTP/2 client or browser that supports HTTP/2. Check for any errors in the console and ensure that the application responds correctly.

    bash
    curl -I --http2 https://localhost:3000
  5. 5

    Monitor Performance and Logs

    After deploying the application, monitor performance metrics and logs to ensure that HTTP/2 is functioning as expected and to identify any potential issues.

    javascript
    // Use logging middleware to monitor requests
    app.use((req, res, next) => {
      console.log(`Request: ${req.url}`);
      next();
    });

Validation

Confirm that the application is accessible via HTTP/2 by using a compatible client or browser. Check the response headers for 'HTTP/2' and ensure that there are no errors in the console. Additionally, monitor logs for any unexpected behavior.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

expressnode.jsapifuture