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

@nuxt/h2

v0.2.0

Published

Tiny JavaScript Server

Downloads

12

Readme

d v b a c

h2 - Tiny JavaScript Server

What?

  • Works perfectly with Serverless, Workers and NodeJS
  • Compatible with connect/express middleware
  • Tree-shakable and zero-dependency
  • Promise and aync/await support
  • Lazy loading
  • Quick prefix router
  • Custom route matcher

See un for workers support

Install

yarn add @nuxt/h2
# or
npm install @nuxt/h2

Usage

Using listhen:

const { createApp } = require('@nuxt/h2')
const { listen } = require('listhen')

const app = createApp()
app.use('/', () => 'Hello world!')

listhen(app)

Using plain node:

const { Server } = require('http')
const { createApp } = require('@nuxt/h2')

const app = createApp()

// Handle can directly return object or Promise<object> for JSON response
app.use('/api', (req) => ({ url: req.url }))

// You can have better matching other than quick prefix match
app.use('/odd', () => 'Is odd!', { match: url => url.substr(1) % 2 })

// Handle can directly return string for HTML response
app.use(() => '<h1>Hello world!</h1>')

// You can chain calls to .use()
app.use('/1', () => '<h1>Hello world!</h1>').use('/2', () => '<h1>Goodbye!</h1>')

// If handle is already async, using useAsync to avoid unnecessary promisify wrapper
// (Shortcut to pass { promisify: false })
// app.useAsync(async () => {})

// Lazy loading routes using { lazy: true }
// app.use('/big', () => import('./big'), { lazy: true })

const port = process.env.PORT || 3000
const server = new Server(app)

server.listen(port, () => {
  console.log(`Listening on: http://localhost:${port}`)
})

Technical

There are two vital parts that make it working: Stack Runner (App), and promisifyHandle.

App

App is basically a http server handle with req, res and attached utilities that runs a stack of middleware/handles in parallel. It will stop when the writableEnded flag is set on a response (which means that res.end has been called) and throw a 404 if writableEnded flag has not been set by the end.

Additionally the app has a quick prefix matcher and will automatically call res.end if any stack layers return a value.

promisifyHandle

Converts a classic middleware (req, res, next?) into a promisified version ready to use with App

  • If middleware has 3rd next/callback param, promise will resolve/reject when called
  • If middleware returns a promise, it will be chained to main promise
  • If calling middleware throws an immediate error, promise will be rejected
  • On close and error events of res, promise will resolve/reject (to ensure if middleware simply calls res.end)

When calling app.use, middleware will be automatically promisified.

If you are already making an async aware middleware, you can use app.useAsync

License

MIT