http-hash-router is a lightweight server-side routing utility for Node.js's native `http` module, built upon the `http-hash` package for pattern matching. It is currently at version 2.0.1 and appears to be a stable, mature package primarily designed for CommonJS environments, indicated by its `require` syntax in examples. While specific release cadence isn't published, its current version and historical usage patterns suggest a focus on stability rather than frequent feature updates. It provides a simple API to define routes using patterns (including parameters and splats) and associate them with request handlers. A key differentiator is its callback-based error handling, specifically designed to integrate directly into Node.js's HTTP server callback without introducing a complex middleware stack. It explicitly manages `404 Not Found` errors and provides a structured way to access URL parameters within handlers, making it suitable for minimalistic HTTP service implementations.
npm install http-hash-routerVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a basic HTTP server with `http-hash-router`, defining two routes (one static, one with a parameter), and handling errors including 404s via a callback.
Always pass a callback function as the fourth argument to `router(req, res, opts, onError)` to handle potential errors, including 404 Not Found errors.
For ESM projects, consider using a CommonJS compatibility layer or bundler to consume this package. Alternatively, explore modern routing libraries built with native ESM support.
Ensure your application explicitly handles errors within the callback passed to the router. Convert callback-based handlers to Promises if integrating with an `async/await` codebase.
Always provide a callback as the fourth argument to the `router` function, e.g., `router(req, res, {}, onError);`. This callback will receive any errors, including `NotFoundError` (for 404s), or will be passed to your route handler if no error occurred.Use the CommonJS `require()` syntax: `const HttpHashRouter = require('http-hash-router');` instead of `import HttpHashRouter from 'http-hash-router';`.