![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Route matching and testing, nothing more than that. As simple as it could be.
Routable is a lightweight regular expression inspired HTTP route parser for Node.js. It only has one goal and that is to match and parse URL's for frameworks.
The module is released in the npm
registry as routable
:
npm install --save routable
The --save
automatically adds the routable module to your package.json.
All the examples in this getting started assume that you have included the
module in your code and exposed it as a Routable
variable:
'use strict';
var Routable = require('routable');
To create a new route simply construct a new Routable
instance with an URL
pattern:
var foo = new Routable('/foo');
There are different patterns that can be used for testing against URL's. Routable supports testing against strings, Regular Expressions and even xRegExp based expressions. See patterns for more details.
Now that you've created your first Routable
instance you can use it to test
against URL's. To see if a URL matches the your Routable
instance you can use
the Routable#test
method:
Just like the RegularExpression.test
method, it returns a boolean indicating
if the given string matches the expression or not. The same is true for
Routable
but instead of testing a Regular Express you're testing your pattern.
var foo = new Routable('/foo');
foo.test('/bar'); // false;
foo.test('/foo'); // true;
foo.test('/fooo'); // false;
While quickly testing an URL is useful sometimes you also want to parse out the
information from the URL. If you have a capturing or named Regular Expression or
string you can use the routable#exec
With normal RegularExpression.exec
you can either undefined
or an Array
with results as return value. With a Routable
instance you still get
undefined
when there isn't a match but instead of an array you receive an
Object
.
var foobar = new Routable('/foo/:bar');
var res = foobar.exec('/foo/foo');
console.log(res.bar); // 'foo'
/\/foo/
./\/(foo|bar)\/bar/
./foo/:bar/1/:baz
./foo/:bar?
./foo/bar
MIT
FAQs
Route matching and testing, nothing more than that. As simple as it could be.
The npm package routable receives a total of 744 weekly downloads. As such, routable popularity was classified as not popular.
We found that routable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.