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

@centralping/ergo-router

v0.1.0-beta.1

Published

REST-compliant router for ergo with strict Fast Fail semantics

Readme

CI codecov npm version OpenSSF Scorecard Node.js >=22 License: MIT

A REST-compliant router for ergo with strict Fast Fail semantics. Provides path matching via find-my-way, automatic REST compliance (405+Allow, HEAD, OPTIONS, PATCH enforcement), transport-level security, and seamless integration with ergo's composable middleware pipeline.

Why ergo-router?

  • Automatic REST compliance -- 405 Method Not Allowed with Allow header, HEAD falls back to GET, OPTIONS auto-responds with allowed methods, PATCH Content-Type enforcement. All per RFC 9110.
  • Transport-level security -- Security headers, CORS, rate limiting, and request ID generation run before routing, ensuring every response (including errors) is protected.
  • Declarative pipeline assembly -- Define routes with a config object; the router assembles the full Fast Fail pipeline (negotiation, auth, validation, execution) from ergo middleware automatically.
  • Graceful shutdown -- Built-in support for draining in-flight requests on SIGTERM/SIGINT.

Request Dispatch Flow

Incoming Request
  |
  +- 1. Transport Layer (every request)
  |    +- Request ID generation (response header)
  |    +- Security headers
  |    +- Rate limiting (429 short-circuit)
  |    +- CORS (preflight 204 short-circuit)
  |
  +- 2. REST Semantics
  |    +- OPTIONS -> 204 + Allow header
  |    +- PATCH Content-Type enforcement -> 415
  |    +- HEAD -> falls back to GET handler
  |    +- Route matching (find-my-way)
  |    +- 405 + Allow or 404
  |
  +- 3. Application Pipeline
       +- Route params seeded in accumulator
       +- Stage 1: Negotiation
       +- Stage 2: Authorization
       +- Stage 3: Validation
       +- Stage 4: Execution
       +- Implicit send()

Every early exit (429, 403, 404, 405, 415, preflight 204) includes security headers and request ID automatically.

Installation

npm install @centralping/ergo-router @centralping/ergo find-my-way

Requires Node.js >= 22. @centralping/ergo is a peer dependency.

Quick Start

import createRouter from '@centralping/ergo-router';

const router = createRouter({
  transport: {
    requestId: {},
    security: {},
    cors: {origin: 'https://myapp.com'}
  },
  defaults: {
    accepts: {types: ['application/json']},
    timeout: {ms: 30000}
  }
});

router.get('/users/:id', {
  execute: (req, res, acc) => ({body: {id: acc.route.params.id}})
});

router.post('/users', {
  validate: {body: {type: 'object', properties: {name: {type: 'string'}}, required: ['name']}},
  execute: (req, res, acc) => ({statusCode: 201, body: acc.body.parsed})
});

router.listen(3000, () => console.log('Listening on :3000'));

API Overview

createRouter(options?)

Creates a new router instance with optional transport and default middleware configuration.

| Option | Description | |---|---| | transport.requestId | Request ID generation config | | transport.security | Security headers (HSTS, CSP, etc.) | | transport.cors | CORS configuration | | transport.rateLimit | Rate limiting (sliding window) | | defaults.* | Default middleware options applied to all routes |

Route Methods

router.get(path, config)
router.post(path, config)
router.put(path, config)
router.patch(path, config)
router.delete(path, config)

Route Config

| Key | Description | Standard | |---|---|---| | execute | Route handler function (required) | -- | | validate | JSON Schema for body/query validation | -- | | accepts | Content negotiation override | RFC 9110 §12.5 | | authorization | Auth strategy override | RFC 6750, RFC 7617 | | timeout | Request timeout override | -- | | precondition | 428 enforcement | RFC 6585 §3 | | rateLimit | Per-route rate limit override | RFC 6585 §4 |

graceful(server, options?)

Graceful shutdown helper. Stops accepting new connections and drains in-flight requests.

import createRouter, {graceful} from '@centralping/ergo-router';
const router = createRouter({...});
const server = router.listen(3000);
graceful(server);

See the full API reference for detailed options and examples.

Standards Compliance

| RFC / Standard | Description | ergo-router Feature | |---|---|---| | RFC 9110 | HTTP Semantics | 405+Allow, HEAD/OPTIONS/PATCH enforcement | | RFC 9457 | Problem Details for HTTP APIs | Structured error responses | | RFC 6797 | HTTP Strict Transport Security | Transport security headers | | RFC 6585 | Additional HTTP Status Codes | Rate limiting (429) | | Fetch Standard | CORS Protocol | Transport CORS handling |

Documentation

Development

npm install
npm test            # lint + format check + tests with coverage
npm run test:watch  # watch mode
npm run lint        # ESLint
npm run format      # Prettier

License

MIT © 2019-present Jason Cust