path-to-regexp is a path parsing library that converts path strings with parameters into regular expressions for matching and route compilation.
The library solves the problem of matching dynamic URL paths against patterns and extracting named parameters from them. It works by parsing path strings that use a simple syntax—colons for named parameters like `:name`, asterisks for wildcard parameters that span segments, and braces for optional path segments—then converting these into regular expressions and metadata that can match incoming paths and extract their parameter values. The tool also provides a reverse operation through its compile function, which transforms parameter objects back into valid path strings.
Developers should choose this tool when building routers or path-matching systems in Node.js applications, particularly in Express-based frameworks where this pattern is standard. It handles the common case of ordered path data well, but the README explicitly notes it is not suitable for arbitrarily ordered data like query strings, URL fragments, or JSON. The library offers configuration options for case sensitivity, delimiter characters, and trailing slash handling, and supports custom encoding and decoding functions for parameter values. Developers working with paths containing special characters like emoji should consider using the recommended encodeurl library alongside it.
The project maintains a stable, focused codebase written in TypeScript that has established itself as a foundational utility in the Node.js routing ecosystem. Development activity shows consistent maintenance with attention to edge cases and developer experience, including detailed documentation of the parse, match, compile, and stringify functions. The maintainers provide clear guidance on usage patterns, such as when to disable encoding and decoding for path rewriting scenarios, and support custom path syntaxes for applications that cannot use the standard format.