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

@express-ts-rpc/router

v0.1.0

Published

Type-safe Express router with Hono-style type inference

Readme

Typed Router for Express

A TypeScript-first router for Express that provides Hono-style type inference. Get full type safety for request parameters, query strings, request bodies, and responses - all while keeping the Express ecosystem you know and love.

Features

  • 🎯 Full type inference for routes, similar to Hono
  • 🔒 Type-safe request parameters, query strings, bodies, and responses
  • 🔌 Drop-in replacement for Express Router
  • 📦 Zero runtime overhead
  • 🛠 Works with existing Express middleware

Installation

npm install express-ts-rpc-express

Quick Start

import { TypedRouter } from "express-ts-rpc-express";

const router = new TypedRouter();

// Type-safe route definition
router.get<
  "/users/:id", // Path with params
  { fields?: string[] }, // Query params
  never, // No request body for GET
  { name: string; age: number } // Response shape
>("/users/:id", async (req, res) => {
  const { id } = req.params; // id is typed
  const { fields } = req.query; // fields is typed as string[] | undefined

  return res.json({
    name: "John",
    age: 30,
    // TypeScript error if response shape doesn't match
  });
});

// Attach to Express app
app.use(router.routes());

Detailed Usage

Route Type Parameters

Each route method (get, post, put, patch, delete) accepts four type parameters:

router.post<
  Path, // Literal path string with params (e.g. '/users/:id')
  Query, // Query string parameters
  Body, // Request body shape
  Response // Response body shape
>;

Example Controller

const userRouter = new TypedRouter()
  // GET /users?role=admin
  .get<"/users", { role?: "admin" | "user" }, never, User[]>("/users", async (req, res) => {
    const { role } = req.query; // typed as 'admin' | 'user' | undefined
    const users = await User.findAll({ role });
    return res.json(users);
  })

  // POST /users
  .post<"/users", never, { name: string; email: string }, { id: string }>("/users", async (req, res) => {
    const { name, email } = req.body; // fully typed
    const user = await User.create({ name, email });
    return res.status(201).json({ id: user.id });
  });

export { userRouter };

Attaching to Express App

import express from "express";

import { userRouter } from "./controllers/user";

const app = express();

// Standard Express middleware
app.use(express.json());

// Attach typed router
app.use(userRouter.routes());

Type Inference

The library provides full type inference for:

  • URL Parameters (:id, etc.)
  • Query String Parameters
  • Request Body
  • Response Body
  • Error Responses

This enables excellent IDE support and catches type errors at compile time.

Contributing

Contributions are welcome! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT Licensed. See LICENSE for details.

Roadmap

  • Add a ValidatedRouter export that uses our types and typia for runtime validation of params

    • If this works we should be able to generate an openAPI spec from a typed router
  • add more overloads for omiting different type args

    • at the moment you have to pick between fully infering route type and fully decaring them. This leads to an akward case of wanting infered response types but wanting to type the query params and body
  • add support for a validation middleware similar to zValidator for hono.

  • This package is designed for proejcts that want the type saftey and dx of projects like trpc and hono but are too large or have too many express depended code to transition. For projects that are too large, it should be possible to write a codemond script that will migrate a type-router express project to hono. Hono is very similar to express in most ways so this should be doable