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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@superfunctions/http-express

v0.1.2

Published

Express adapter for @superfunctions/http

Readme

@superfunctions/http-express

Express adapter for @superfunctions/http - Use framework-agnostic routers with Express.

Installation

npm install @superfunctions/http @superfunctions/http-express express

Quick Start

import express from 'express';
import { createRouter } from '@superfunctions/http';
import { toExpress } from '@superfunctions/http-express';

// Define your router (framework-agnostic)
const apiRouter = createRouter({
  routes: [
    {
      method: 'GET',
      path: '/users/:id',
      handler: async (req, ctx) => {
        return Response.json({ id: ctx.params.id });
      },
    },
  ],
});

// Use with Express
const app = express();
app.use(express.json()); // Important: Add body parser
app.use('/api', toExpress(apiRouter));
app.listen(3000);

API

toExpress(router)

Converts a @superfunctions/http router to an Express RequestHandler.

Parameters:

  • router: Router instance from @superfunctions/http

Returns: express.RequestHandler

Example:

import { toExpress } from '@superfunctions/http-express';

app.use('/api', toExpress(myRouter));

Usage Examples

With Middleware

import { createRouter } from '@superfunctions/http';
import { toExpress } from '@superfunctions/http-express';

const router = createRouter({
  middleware: [
    async (req, ctx, next) => {
      // Auth middleware
      const token = req.headers.get('Authorization');
      if (!token) {
        return Response.json({ error: 'Unauthorized' }, { status: 401 });
      }
      return next();
    },
  ],
  routes: [
    {
      method: 'GET',
      path: '/protected',
      handler: async () => Response.json({ data: 'secret' }),
    },
  ],
});

app.use('/api', toExpress(router));

With Custom Context

interface AppContext {
  db: Database;
}

const router = createRouter<AppContext>({
  context: { db: myDatabase },
  routes: [
    {
      method: 'GET',
      path: '/users',
      handler: async (req, ctx) => {
        const users = await ctx.db.findMany({ model: 'users' });
        return Response.json(users);
      },
    },
  ],
});

app.use('/api', toExpress(router));

Multiple Routers

const usersRouter = createRouter({ routes: [/* user routes */] });
const postsRouter = createRouter({ routes: [/* post routes */] });

app.use('/api/users', toExpress(usersRouter));
app.use('/api/posts', toExpress(postsRouter));

Important Notes

Body Parsing

You must add Express body parsing middleware before using the adapter:

app.use(express.json()); // For JSON bodies
app.use(express.urlencoded({ extended: true })); // For form data

Error Handling

The adapter automatically handles errors from your route handlers. You can add Express error middleware for additional handling:

app.use((err, req, res, next) => {
  console.error('Express error:', err);
  res.status(500).json({ error: 'Server error' });
});

Route Paths

Routes are registered relative to the mount point:

const router = createRouter({
  routes: [
    { method: 'GET', path: '/hello', handler: () => Response.json({ msg: 'hi' }) }
  ]
});

// Route accessible at: /api/hello
app.use('/api', toExpress(router));

TypeScript

Full TypeScript support with proper types:

import type { Router } from '@superfunctions/http';
import type { RequestHandler } from 'express';

const myRouter: Router = createRouter({ routes: [...] });
const handler: RequestHandler = toExpress(myRouter);

Compatibility

  • Express 4.x ✅
  • Express 5.x ✅

License

MIT