http-hash is an HTTP router for Node.js that organizes routes into a strict path tree structure, enabling resolution independent of definition order. Unlike traditional regex-based routers where route order can affect matching, http-hash segments paths (e.g., `/foo/bar` becomes `foo > bar`) to build a tree, supporting static segments, named parameters (`:param`), and splats (`*`). This approach simplifies reasoning about route precedence. The current stable version is 2.0.1, last published approximately 7 years ago (as of April 2026), indicating a long-abandoned project with infrequent or no further development. It primarily targets CommonJS environments.
npm install http-hashVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create an http-hash router, define routes with named parameters and splats, and retrieve route information, including handling missing routes.
Ensure all paths are unique and adhere to the `/segment/:param/*splat` structure. Test route additions to catch conflicts early.
Use `const HttpHash = require('http-hash');` in CommonJS modules. For ESM projects, consider using a bundler like Webpack or Rollup, or an alternative ESM-compatible router.Design routes explicitly considering empty segments or trailing slashes if such distinctions are critical for your application logic. Always normalize paths before routing if strict trailing slash behavior is desired.
For new projects, consider more actively maintained HTTP routing libraries. For existing projects, be aware of potential long-term maintenance and security implications.
Review your route definitions and ensure each path is unique and does not create an ambiguous match for the router. For example, `/foo/:id` and `/foo/:name` might conflict if not carefully designed with static segments.
If in a CommonJS file, ensure `const HttpHash = require('http-hash');` is used. If in an ESM file, either switch to a CommonJS file, use a bundler that handles CJS-to-ESM conversion, or use an alternative router that natively supports ESM.The library exports a function that acts as a factory for router instances. Call `HttpHash()` directly without the `new` keyword: `const hash = HttpHash();`
No dependency data recorded yet.