node-http2

4.0.1 · abandoned · verified Tue Apr 21

The `node-http2` package (version 4.0.1) provides a pure JavaScript implementation of the HTTP/2 client and server protocols, aiming for API compatibility with Node.js's standard HTTPS module. Originally forked from `molnarg/node-http2`, this specific `kaazing/node-http2` version was released around 2017. Its primary differentiating features were its full JavaScript implementation and inclusion of server push capabilities prior to widespread native HTTP/2 support in Node.js. However, since Node.js v8.0.0 (released May 2017) included experimental built-in HTTP/2 support, and especially with its stabilization in Node.js v10.0.0, this package has been superseded. As such, it is no longer actively maintained and should generally not be used in new projects.

Common errors

Warnings

Install

Imports

Quickstart

Starts an HTTPS/2 server on port 8080 using `node-http2`, serving a 'Hello world' response. Requires self-signed certificates for local testing.

const fs = require('fs');
const http2 = require('node-http2'); // Explicitly import this package

// Ensure you have localhost.key and localhost.crt in an 'example' directory
// For testing, you can generate self-signed certificates:
// openssl genrsa -out example/localhost.key 2048
// openssl req -new -x509 -key example/localhost.key -out example/localhost.crt -days 365 -subj "/CN=localhost"

const options = {
  key: fs.readFileSync('./example/localhost.key'),
  cert: fs.readFileSync('./example/localhost.crt')
};

http2.createServer(options, function(request, response) {
  response.end('Hello world from node-http2!');
}).listen(8080, () => {
  console.log('node-http2 server listening on port 8080 (HTTPS/2)');
  console.log('Try: curl --http2 -k https://localhost:8080/');
});

view raw JSON →