Turn a path string such as `/user/:name` into a regular expression
8.6k
Stars
487
Forks
13
Open issues
30
Contributors
AI Analysis
path-to-regexp converts path strings with parameters (like `/user/:name`) into regular expressions for routing. It is a foundational utility library widely used in Node.js web frameworks, particularly Express.js, to parse and match URL paths. It serves developers building HTTP routers and URL matching systems, not end-users or general audiences.
Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.
AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.
path-to-regexp: The URL routing primitive quietly powering most of the Node.js ecosystem
path-to-regexp converts URL path strings like `/user/:name` into regular expressions, enabling named parameter extraction, optional segments, and wildcard matching. It is a foundational dependency used internally by Express.js, Koa, and numerous other routing frameworks, meaning most Node.js applications rely on it indirectly. Its primary audience is framework authors and developers building custom routers or middleware. The library has stabilized around a clean API with `match`, `compile`, `parse`, and `stringify` functions, making it useful both as a direct tool and as an embedded routing primitive.
Created in August 2012 under the pillarjs organization (closely linked to Express.js development), it has evolved over 13+ years from a simple regex utility into a well-specified routing primitive, with breaking changes over major versions tightening syntax to reduce ambiguity.
Growth is largely structural: as Express.js adoption grew globally, path-to-regexp was pulled along as a transitive dependency. Direct stars (8,597) underrepresent actual reach — npm download counts are in the hundreds of millions per month. Recent star velocity (2/week as of mid-2026) reflects saturation, not decline. The library is in a maintenance phase appropriate for its maturity.
Strong indirect adoption evidence: path-to-regexp is a direct dependency of Express.js (the most-downloaded Node.js framework), meaning it is transitively present in a large fraction of all Node.js production deployments worldwide. npm download counts are publicly verifiable and consistently in the hundreds of millions per month range. Direct use by framework authors is well-documented across the ecosystem.
Appears to be a single-purpose TypeScript library exposing a small, composable API surface: parse (string → TokenData), pathToRegexp (path → RegExp + keys), match (path → match function), compile (path → path-builder function), and stringify (TokenData → string). The TokenData intermediate representation likely enables advanced use cases like custom path formats. Architecture appears deliberately minimal and dependency-light.
Build coverage badge is referenced in the README, suggesting automated coverage reporting is in place. Specific coverage percentage is not documented in the README excerpt.
Last push was 2026-06-01, approximately 23 days before the evaluation date — this is actively maintained. Given its age and stability, low commit frequency is expected and appropriate rather than concerning. The README references error improvements and breaking changes from past releases, indicating ongoing intentional stewardship.
ADOPT IF: you are building a router, framework, or any system requiring structured URL path matching with named parameters in Node.js — this is the established, battle-tested choice. AVOID IF: you are targeting environments where the native URLPattern API is available and sufficient, or if you need query string or fragment matching (explicitly out of scope per README). MONITOR IF: you are building for edge runtimes or Deno where native URL APIs are maturing and may reduce dependency on this library over time.
Independent dimensions
Mainstream potential
4/10
Technical importance
8/10
Adoption evidence
9/10
- Breaking changes between major versions (the README explicitly notes that ambiguous paths that previously worked now throw errors), which can cause unexpected failures when upgrading transitive dependencies.
- The native URLPattern Web API is gaining traction in modern runtimes (browsers, Deno, Cloudflare Workers) and could reduce demand for this library in non-Node.js environments over a 2-5 year horizon.
- As a transitive dependency of Express.js, its version may be pinned by upstream frameworks independently of your own upgrade path, leading to version conflicts in complex dependency trees.
- Narrow scope by design — it explicitly does not handle query strings, fragments, or unordered data, which can surprise developers expecting a full URL parsing solution.
- Low direct star growth suggests limited new direct adoption; future relevance likely depends on continued dominance of Express.js and Koa in the Node.js ecosystem.
Likely to remain a stable, low-churn infrastructure component for as long as Express.js remains dominant in Node.js. Gradual displacement possible in newer runtimes as native URL APIs mature, but no near-term risk of obsolescence.
Newsletter
Get analyses like this every Monday
Free weekly digest of the most interesting open-source discoveries.
Languages
Information
- Language
- TypeScript
- License
- MIT
- Last updated
- 2w ago
- Created
- 170mo ago
- Analyzed with
- anthropic/claude-haiku-4-5
Stars over time
Contributors over time
Top 100 contributors only — repos with more will plateau at 100.
Open issues
Top contributors
Recent releases
Similar repos
expressjs/cookie-parser
cookie-parser is a lightweight Express.js middleware that parses HTTP Cookie...
express-validator/express-validator
express-validator is an Express.js middleware that integrates validator.js for...
| Repository | Stars | Week Δ | Language | Score | Updated |
|---|---|---|---|---|---|
|
|
8.6k | +1 | TypeScript | 8/10 | 2w ago |
|
|
4.3k | — | TypeScript | 8/10 | 1w ago |
|
|
2k | — | JavaScript | 8/10 | 1mo ago |
|
|
5.5k | — | JavaScript | 9/10 | 1d ago |
|
|
6.2k | — | TypeScript | 8/10 | 2w ago |
|
|
10.3k | — | JavaScript | 7/10 | 12mo ago |
Hand-rolled regex solutions lack named parameter extraction, optional groups, and the compile/reverse capability. path-to-regexp provides a tested, specification-level abstraction that manual regex cannot easily replicate.
URLPattern is a native browser/Deno API with similar goals but different syntax and no compile/reverse function. path-to-regexp has broader Node.js compatibility and a richer API surface, though URLPattern may reduce the need for this library in future runtimes.
Solves a complementary problem (query string parsing), not a competing one. Both are often used together in routing contexts.
Trouter is a lightweight router that internalizes its own path matching rather than delegating to path-to-regexp. Suitable for simple cases but lacks the API depth for framework-level use.
Operates at a different layer (input validation after routing), not a routing primitive. Not a true competitor but often co-deployed in Express apps.