Registry / http-networking / http-hash

http-hash

JSON →
library2.0.1jsnpmunverified

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-hash
INSTALL
IMPORT
SIG · HTTP-HASH
H
http-hash
http-networkingjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HttpHash
const HttpHash = require('http-hash');
import HttpHash from 'http-hash';
This library is CommonJS-only. Direct ESM import will not work without a bundler or compatibility layer.
hash.set
hash.set('/path/:param', handler);
hash.set('/path/:param', handler, { order: 1 });
Routes are order-independent; 'order' is not a valid option and conflicts will throw errors.
hash.get
const route = hash.get('/path/value');
const handler = hash.get('/path/value').handler();
The `get` method returns an object containing the handler, params, and splat, not just the handler. Always check if `route.handler` is `null` for missing routes.

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.

const HttpHash = require('http-hash'); // Create a new http hash instance const hash = HttpHash(); // Define a route with a named parameter hash.set('/test/:foo/', (req, res) => { res.end(`Hello from /test/${req.params.foo}`); }); // Define a route with a splat parameter hash.set('/files/*', (req, res) => { res.end(`Serving file: ${req.splat}`); }); // Get and use a valid route let route1 = hash.get('/test/variable-value'); console.log('Route 1 Handler:', route1.handler ? 'Found' : 'Not Found'); console.log('Route 1 Params:', route1.params); // { foo: 'variable-value' } // Get and use a splat route let route2 = hash.get('/files/path/to/document.txt'); console.log('Route 2 Handler:', route2.handler ? 'Found' : 'Not Found'); console.log('Route 2 Splat:', route2.splat); // path/to/document.txt // Get an invalid route let missingRoute = hash.get('/non-existent'); console.log('Missing Route Handler:', missingRoute.handler ? 'Found' : 'Not Found'); // Not Found
Debug
Known issues
breakingAdding a route that conflicts with an existing path will throw an exception. This includes conflicting variable names or malformed splat routes (e.g., '*' not at the end).
fix
Ensure all paths are unique and adhere to the `/segment/:param/*splat` structure. Test route additions to catch conflicts early.
affects: >=1.0.0
gotchaThis package is CommonJS-only. Attempting to `import` it directly in a native ES Module (ESM) environment will result in errors unless transpiled by a bundler or run in Node.js with specific compatibility flags.
fix
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.
affects: >=1.0.0
gotchaTrailing slashes generally do not matter for matching, but variables and splats will not match empty strings. A splat value does not include the leading slash as it is consumed by the parent node.
fix
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.
affects: >=1.0.0
deprecatedThe package has not been updated in approximately 7 years (last published December 2018). While functional, it is considered abandoned and may not receive future updates, bug fixes, or security patches.
fix
For new projects, consider more actively maintained HTTP routing libraries. For existing projects, be aware of potential long-term maintenance and security implications.
affects: >=2.0.1
Errors
Common errors & fixes
Error: Path conflict: tried to add path '/foo/:bar' but found conflicting route
Attempted to add a new route that overlaps or conflicts with an already defined route in the hash table.
fix
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.
ReferenceError: require is not defined
The `http-hash` package uses CommonJS module syntax (`require`), but you are attempting to use it in an ES Module (ESM) context without a transpiler or specific Node.js configuration.
fix
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.
TypeError: HttpHash is not a constructor
You are attempting to instantiate `HttpHash` using `new HttpHash()` instead of calling it as a factory function.
fix
The library exports a function that acts as a factory for router instances. Call `HttpHash()` directly without the `new` keyword: `const hash = HttpHash();`
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
http-hash — npm install http-hash · libregistry