koa-path-match is a lightweight routing middleware designed for Koa.js applications, currently stable at version 5.0.0. It functions as a minimalist path matcher built on top of the `path-match` library, which itself uses `path-to-regexp` for robust URL pattern matching, mirroring the routing logic found in Express.js. This package distinguishes itself by offering fine-grained control over HTTP method handling and advocating for a single-function-per-route paradigm, intentionally omitting the `next` parameter in method-specific middleware to streamline logic. Its release cycle is closely tied to major version updates of its core `path-to-regexp` dependency. It serves as an efficient solution for basic route dispatching without the complexity of a full-featured routing framework, suitable for microservices or simple API endpoints.
npm install koa-path-matchVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to set up a basic Koa application using `koa-path-match` for method-specific routing and parameter extraction.
Upgrade your Node.js environment to version 18 or higher, or pin `koa-path-match` to version 3.x for older Node.js environments.
Review the changelogs for `path-to-regexp` when upgrading major versions. Thoroughly test existing routes, particularly those with advanced regex patterns or custom options, after an upgrade.
Be aware of potential key collisions in `ctx.params`. If you need to preserve existing keys, manually merge or rename them before `koa-path-match` sets its parameters, or use unique parameter names in your routes.
If you require middleware chaining or explicit `next()` calls, define your middleware using the `app.use(route(path, fns...))` syntax with an array of middleware, or structure your application such that each route handler is self-contained.
If your project uses `type: "module"` in `package.json` or `.mjs` files, change `const route = require('koa-path-match')()` to `import routeFactory from 'koa-path-match'; const route = routeFactory();`Ensure you are calling the imported default export: `import routeFactory from 'koa-path-match'; const route = routeFactory();` instead of `import route from 'koa-path-match';`
Update your Node.js environment to version 18 or newer (e.g., using `nvm install 18 && nvm use 18`) or downgrade `koa-path-match` to version 3.x if you cannot upgrade Node.js.