{"id":16030,"library":"find-my-way","title":"Find My Way HTTP Router","description":"find-my-way is a high-performance HTTP router for Node.js, currently at version 9.5.0, designed for speed using a Radix Tree implementation. It is framework-independent and supports advanced routing features such as route parameters, wildcards, and versioned routes. The project maintains an active release cadence, with recent updates focusing on performance improvements, Node.js version compatibility (requiring Node.js >=20), and security fixes. Key differentiators include its proven speed, demonstrated in benchmarks against other popular routers, and its direct use in major frameworks like Fastify and Restify, indicating robustness and reliability for production environments. It also provides a comprehensive API for route management including `on`, `off`, `findRoute`, `hasRoute`, and `lookup`.","status":"active","version":"9.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/delvedor/find-my-way","tags":["javascript","http","router","radix","fast","speed","typescript"],"install":[{"cmd":"npm install find-my-way","lang":"bash","label":"npm"},{"cmd":"yarn add find-my-way","lang":"bash","label":"yarn"},{"cmd":"pnpm add find-my-way","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The default export is typically a class constructor. While `require('find-my-way')()` works for CommonJS, modern ESM/TypeScript usage often involves `new FindMyWay()` or calling the default export directly as a function that returns an instance. Fastify uses `new FindMyWay()` for instantiation.","wrong":"import { FindMyWay } from 'find-my-way';","symbol":"FindMyWay","correct":"import FindMyWay from 'find-my-way';\nconst router = new FindMyWay();"},{"note":"Imports for types should use `import type` to ensure they are stripped from the JavaScript output, preventing runtime errors or unnecessary bundle size.","wrong":"import { FindMyWayOptions } from 'find-my-way';","symbol":"FindMyWayOptions","correct":"import type { FindMyWayOptions } from 'find-my-way';"},{"note":"For CommonJS, `require('find-my-way')` returns the constructor function directly, which is then typically called without `new` to create an instance, as shown in the package's own usage examples. `new` also works.","wrong":"const { FindMyWay } = require('find-my-way');","symbol":"CommonJS require","correct":"const FindMyWay = require('find-my-way');\nconst router = FindMyWay();"}],"quickstart":{"code":"const http = require('http')\nconst FindMyWay = require('find-my-way')\nconst router = FindMyWay()\n\nrouter.on('GET', '/', (req, res, params) => {\n  res.end('{\"message\":\"hello world\"}')\n})\n\nrouter.on('GET', '/user/:id', (req, res, params) => {\n  res.end(`{\"message\":\"hello user ${params.id}\"}`)\n})\n\nrouter.on('POST', '/data', (req, res) => {\n  let body = ''\n  req.on('data', chunk => { body += chunk })\n  req.on('end', () => {\n    res.end(`Received data: ${body}`)\n  })\n})\n\nconst server = http.createServer((req, res) => {\n  router.lookup(req, res)\n})\n\nserver.listen(3000, err => {\n  if (err) throw err\n  console.log('Server listening on: http://localhost:3000')\n  console.log('Try visiting http://localhost:3000 and http://localhost:3000/user/123')\n  console.log('Or curl -X POST -d \"test\" http://localhost:3000/data')\n})","lang":"javascript","description":"Demonstrates basic HTTP server creation, defining GET and POST routes, handling route parameters, and using `find-my-way`'s `lookup` method to dispatch incoming requests."},"warnings":[{"fix":"Ensure your code handles route parameter objects as 'null objects', particularly when using `Object.prototype` methods. Use `Object.prototype.hasOwnProperty.call(params, key)` if checking for own properties.","message":"The behavior of parameter objects changed in `v9.0.0`. Previously, route parameters might have been regular objects, but they are now 'null objects' (objects created with `Object.create(null)`). This can affect assumptions about prototype chain or methods like `hasOwnProperty` if not accounted for.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Upgrade your Node.js environment to version 20 or newer to use `find-my-way` v9.x and above. Refer to your project's `engines` field in `package.json`.","message":"Node.js version requirements were increased in `v9.0.0`, dropping support for older Node.js runtimes. The package now requires Node.js version 20 or higher.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Upgrade `find-my-way` to `v9.0.1` or `v8.2.2` (or subsequent versions) immediately to mitigate the ReDoS vulnerability.","message":"A security vulnerability (CVE-2024-45813 / GHSA-rrr8-f88r-h8q6) related to a ReDoS (Regular Expression Denial of Service) in multiparametric routes was patched in `v8.2.2` and `v9.0.1`. This could lead to excessive CPU consumption with specifically crafted URLs.","severity":"breaking","affected_versions":"<9.0.1 || <8.2.2"},{"fix":"Configure the `onBadUrl` option when instantiating the router to provide custom error handling for malformed paths, or ensure your `defaultRoute` gracefully handles such cases. Example: `const router = FindMyWay({ onBadUrl: (path, req, res) => { res.statusCode = 400; res.end(`Bad path: ${path}`); } })`.","message":"By default, `find-my-way` invokes a `defaultRoute` for badly formatted URLs (e.g., `/hello/%world`). If not explicitly handled, this might result in a generic 404.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Initialize the router with `ignoreTrailingSlash: true` option to make `/foo` and `/foo/` resolve to the same route. Example: `const router = FindMyWay({ ignoreTrailingSlash: true })`.","message":"Trailing slashes are not ignored by default. A route registered for `/foo` will not match `/foo/`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If using Node.js <22.2.0, avoid the 'QUERY' HTTP method. Upgrade to `find-my-way` `v9.1.0` or newer if using Node.js 22.2.0+ and leveraging the 'QUERY' method.","message":"Node.js `http.METHODS` was updated in Node 22.2.0 to include 'QUERY'. If running an older Node.js version with routes using 'QUERY', it might not be recognized.","severity":"gotcha","affected_versions":"<9.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure you instantiate the router after importing/requiring it: `const FindMyWay = require('find-my-way'); const router = FindMyWay();` or `import FindMyWay from 'find-my-way'; const router = new FindMyWay();`.","cause":"The `find-my-way` module was imported or required but not instantiated correctly. For example, `require('find-my-way')` returns a constructor function, not an instance directly.","error":"TypeError: router.lookup is not a function"},{"fix":"Check for duplicate route registrations. If intentional, use constraints (`{ constraints: { version: '1.0.0' } }`) or ensure paths are unique. For example, `router.on('GET', '/path', handler1)` and `router.on('GET', '/path', handler2)` will cause this error.","cause":"Attempting to register the same HTTP method and path combination more than once without using constraints (like versioning or host-based routing).","error":"Error: Route already registered for method 'GET' with path '/some/path'"},{"fix":"Initialize the router with `ignoreTrailingSlash: true` if you want paths with and without trailing slashes to resolve to the same route. Alternatively, register both `/users` and `/users/` explicitly.","cause":"This often occurs due to trailing slash mismatch. For instance, a route for `/users` won't match a request for `/users/` if `ignoreTrailingSlash` is not enabled.","error":"404 Not Found (for a path that seems to match a registered route)"}],"ecosystem":"npm"}