npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

http2-helper

v1.1.4

Published

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/http2-helper.svg)](https://badge.fury.io/js/http2-helper)

Downloads

33

Readme

Http2 Helper

License: MIT npm version

A decorator based npm package intended to simplify organizing http2 listeners, as well as providing the ability to easily manage multiple http2 client connections.

As of Feb 2021 this package makes heavy use of JavaScript decorators which are currently in stage two proposal. The best way to use them at this time is to compile your TypeScript to ESNext or use Babel. Read more about the proposal here.

Usage

First we need to instantiate a named server. We can do this over http as shown below, or alternatively over https using a cert and key

const server = Http2ServerFactory.Create('test');
server.listen(8000);
const server = Http2ServerFactory.Create('test', key, cert);
server.listen(8000);

@Http2Listener

The first and most central decorator is our Http2Listener. A method with this decorator will be triggered when a stream is instantiated on the server side. The stream and headers arguments will be provided, and our method can use them to interact with the client. Our listeners will be run in the order they are declared, so we can safely handle the initial handshake as part of our first method.

import { Http2ServerFactory, Http2Listener, Http2SessionListener, Http2Poll, Http2ServerBroadcast } from 'http2-helper';

class Example {
  @Http2Listener('test')
  private thisWillBeAStreamHandler(stream, headers) {
    stream.respond({ ':status': 200, 'content-type': 'text/plain' });
    stream.write('hello ');
  };
}

Because listener order is respected we can also use Http2Listeners to build a pipeline for our streams:

class Example {
  @Http2Listener('test')
  private stepOne(stream, headers) {
    stream.respond({ ':status': 200, 'content-type': 'text/plain' });
    stream.write('hello ');
  };
  
  @Http2Listener('test')
  private stepTwo(stream, headers) {
    stream.write('nice to meet you');
  };
  
  @Http2Listener('test')
  private stepThree(stream, headers) {
    stream.write('goodbye');
    stream.end();
  };
}

@Http2Poll

Frequently we might want to have a client connect and receive periodic updates from the server. In that case we can use Http2Poll. The first argument is a name of the specific server we want to be a listener for, and the second argument is the interval on which we want to run our handler. In the example below we will write polling... to the stream every 5 seconds.

@Http2Poll('test', 5000)
private thisWillBeAPollingMethod(stream, headers) {
  stream.write('polling...');
}

@Http2SessionListener

Similar to Http2Listener, Http2SessionListener will trigger when a session event is fired by a newly instantiated stream. This can be used when session data is required.

@Http2SessionListener('test')
private thisWillBeASessionHandler(session) {
  console.log('a session!', session);
}

@Http2ServerBroadcast

Http2ServerBroadcast works in a slightly different way. Rather than being an event handler, a method decorated with this is intended to be called directly. When invoked our method will write the return value to all currently active http2 connections on a server. This can be useful when we want to do something like send a maintenance (or other system wide) alert to all currently active users / connections.

@Http2ServerBroadcast('test')
public broadcastTheOutput() {
  return 'a whole new wooooorld';
}

Misc

If needed we are still able to treat our server instance as a normal http2 server:

const server = Http2ServerFactory.Create('test');
server.listen(8000);

server.on('stream', (stream) => {
  stream.write('we can still do it this way');
});

This allows us to offer flexibility and extensibility to users.