{"id":16380,"library":"http-hash","title":"HTTP Path Tree Router","description":"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.","status":"abandoned","version":"2.0.1","language":"javascript","source_language":"en","source_url":"git://github.com/Matt-Esch/http-hash","tags":["javascript","router","http","path","hash"],"install":[{"cmd":"npm install http-hash","lang":"bash","label":"npm"},{"cmd":"yarn add http-hash","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-hash","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This library is CommonJS-only. Direct ESM import will not work without a bundler or compatibility layer.","wrong":"import HttpHash from 'http-hash';","symbol":"HttpHash","correct":"const HttpHash = require('http-hash');"},{"note":"Routes are order-independent; 'order' is not a valid option and conflicts will throw errors.","wrong":"hash.set('/path/:param', handler, { order: 1 });","symbol":"hash.set","correct":"hash.set('/path/:param', handler);"},{"note":"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.","wrong":"const handler = hash.get('/path/value').handler();","symbol":"hash.get","correct":"const route = hash.get('/path/value');"}],"quickstart":{"code":"const HttpHash = require('http-hash');\n\n// Create a new http hash instance\nconst hash = HttpHash();\n\n// Define a route with a named parameter\nhash.set('/test/:foo/', (req, res) => {\n    res.end(`Hello from /test/${req.params.foo}`);\n});\n\n// Define a route with a splat parameter\nhash.set('/files/*', (req, res) => {\n    res.end(`Serving file: ${req.splat}`);\n});\n\n// Get and use a valid route\nlet route1 = hash.get('/test/variable-value');\nconsole.log('Route 1 Handler:', route1.handler ? 'Found' : 'Not Found');\nconsole.log('Route 1 Params:', route1.params); // { foo: 'variable-value' }\n\n// Get and use a splat route\nlet route2 = hash.get('/files/path/to/document.txt');\nconsole.log('Route 2 Handler:', route2.handler ? 'Found' : 'Not Found');\nconsole.log('Route 2 Splat:', route2.splat); // path/to/document.txt\n\n// Get an invalid route\nlet missingRoute = hash.get('/non-existent');\nconsole.log('Missing Route Handler:', missingRoute.handler ? 'Found' : 'Not Found'); // Not Found","lang":"javascript","description":"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."},"warnings":[{"fix":"Ensure all paths are unique and adhere to the `/segment/:param/*splat` structure. Test route additions to catch conflicts early.","message":"Adding 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).","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Trailing 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For new projects, consider more actively maintained HTTP routing libraries. For existing projects, be aware of potential long-term maintenance and security implications.","message":"The 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.","severity":"deprecated","affected_versions":">=2.0.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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.","cause":"Attempted to add a new route that overlaps or conflicts with an already defined route in the hash table.","error":"Error: Path conflict: tried to add path '/foo/:bar' but found conflicting route"},{"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.","cause":"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.","error":"ReferenceError: require is not defined"},{"fix":"The library exports a function that acts as a factory for router instances. Call `HttpHash()` directly without the `new` keyword: `const hash = HttpHash();`","cause":"You are attempting to instantiate `HttpHash` using `new HttpHash()` instead of calling it as a factory function.","error":"TypeError: HttpHash is not a constructor"}],"ecosystem":"npm"}