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

express-ts-rpc

v1.0.0

Published

Type-safe Express router with Hono-style type inference

Readme

Typed Router for Express

A modern TypeScript wrapper for Express applications that provides end-to-end type safety without requiring major rewrites of existing code.

Background

Node.js and Express revolutionized JavaScript development by enabling isomorphic code. While Express remains widely used and recently released version 5, modern alternatives like Hono and Fastify offer superior TypeScript support and performance benefits.

Several projects attempt to bring end-to-end type safety to Express (like tRPC), but they typically require significant refactoring of existing applications. This library takes a different approach by providing a thin TypeScript wrapper around Express Router, allowing incremental adoption in legacy projects.

Features

  • Drop-in replacement for Express Router with full type inference
  • Compatible with existing Express middleware and plugins
  • Type-safe route parameters, query strings, request bodies, and responses
  • Minimal runtime overhead
  • Inspired by Hono's API design

Usage

The typed router maintains Express's familiar API while adding type safety. Here's a complete example showing both server and client usage:

// Server-side route definition
import { TypedRouter } from "express-ts-rpc/router"

const router = new TypedRouter()

// Define a type-safe route
.get<{
  params: { id: string },
  query: { order?: "desc" | "asc" },
  body: any,
  response: User
}>('/users/:id', async (req, res) => {
  const { id } = req.params; // fully typed
  const { fields } = req.query; // typed as string[] | undefined

  const user = await getUser(id, fields);
  return res.json(user);
});

// Client-side consumption
import axios from 'axios';
import { createAPIClient } from 'express-ts-rpc-client';

const axiosInstance = axios.create({ baseURL: 'http://localhost:3000' });
const apiClient = createAPIClient<typeof router>(axiosInstance);

// Type-safe API calls
const user = await apiClient.users[':id'].get({
  params: { id: '123' },
  // expecting "decs" or "asc" you will get a type error!
  query: { limit: "aasc" }
}); // user is fully typed!

Type Generation

For large APIs, we recommend:

  1. Exporting router types for client-side consumption
  2. Generating .d.ts files for improved IDE performance
  3. Creating separate typed clients for different sections of your API

Example Application

This repository includes a reference implementation demonstrating:

  • Typed Router integration
  • PostgreSQL with PGlite for development
  • Drizzle ORM for type-safe database access
  • Best practices for structuring a modern Express/TypeScript monorepo

Caveats

While the library aims to provide comprehensive type safety, there are some limitations due to working within Express's type system. These are documented in detail in our Caveats section.

When to Use This

  • You have a legacy Express application and want to add type safety incrementally
  • You need to maintain Express compatibility while improving the developer experience
  • You're looking for a stepping stone toward more modern frameworks like Hono

For new projects, we recommend considering modern alternatives like Hono or Fastify that provide better TypeScript support out of the box.

License

MIT