Registry / web-framework / rou3
library0.8.1jsnpmunverified

rou3 is a lightweight and fast JavaScript router, currently at version 0.8.1. It provides efficient routing capabilities for various JavaScript environments including Node.js, Bun, Deno, and browsers. The library is actively maintained with frequent minor releases and bug fixes, often including performance enhancements and type improvements, as seen in recent versions like 0.8.0 and 0.7.12. Key differentiators include its URLPattern-compatible syntax for defining routes, support for complex patterns like named wildcards, optional parameters, and custom regex, as well as features for escaping special characters in paths. It ships with TypeScript types, ensuring a robust developer experience for typed applications.

npm install rou3
INSTALL
IMPORT
SIG · ROU3
R
rou3
web-frameworkjavascriptv0.8.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createRouter
import { createRouter } from 'rou3';
const { createRouter } = require('rou3');
rou3 is primarily designed for ESM environments, though CommonJS usage might be possible via bundlers.
addRoute
import { addRoute } from 'rou3';
import addRoute from 'rou3';
All public API functions are named exports. There is no default export.
findRoute
import { findRoute } from 'rou3';
Used to match an incoming path and method against registered routes.
InferRouteParams
import type { InferRouteParams } from 'rou3';
TypeScript type for extracting route parameters, added in v0.7.6.

Demonstrates creating a router, adding various route patterns including parameters and wildcards, and then using `findRoute` to match incoming requests and extract associated data and parameters.

import { createRouter, addRoute, findRoute } from 'rou3'; const router = createRouter(); // Add various route types addRoute(router, 'GET', '/users', { handler: 'listUsers' }); addRoute(router, 'POST', '/users/:id', { handler: 'createUser' }); addRoute(router, 'GET', '/posts/:category/:slug', { handler: 'viewPost' }); addRoute(router, 'GET', '/files/**:path', { handler: 'serveStatic' }); // Match routes and extract parameters console.log('GET /users:', findRoute(router, 'GET', '/users')); // Expected: { handler: 'listUsers' } console.log('POST /users/123:', findRoute(router, 'POST', '/users/123')); // Expected: { handler: 'createUser', params: { id: '123' } } console.log('GET /posts/tech/my-article:', findRoute(router, 'GET', '/posts/tech/my-article')); // Expected: { handler: 'viewPost', params: { category: 'tech', slug: 'my-article' } } console.log('GET /files/images/logo.png:', findRoute(router, 'GET', '/files/images/logo.png')); // Expected: { handler: 'serveStatic', params: { path: 'images/logo.png' } } console.log('GET /not-found:', findRoute(router, 'GET', '/not-found')); // Expected: undefined
Debug
Known issues
breakingVersion 0.8.0 introduced significant changes to URL pattern compatibility. While aiming for URLPattern API syntax, existing complex patterns might behave differently or require adjustments.
fix
Review your route patterns against the new URLPattern-compatible syntax documentation. Test all existing routes thoroughly after upgrading.
affects: >=0.8.0
gotchaAll paths added to rou3 must begin with a forward slash `/`. Paths like `users` (without a leading slash) will not be correctly registered or matched.
fix
Always prepend a '/' to your route paths, e.g., `/users` instead of `users`.
affects: >=0.1.0
gotchaHTTP methods passed to `addRoute` and `findRoute` must be in UPPERCASE. Using lowercase methods (e.g., 'get' instead of 'GET') will result in routes not being matched.
fix
Ensure all HTTP methods are uppercase, e.g., 'GET', 'POST', 'PUT', 'DELETE'.
affects: >=0.1.0
gotchaIf a route pattern contains literal colons (`:`) or asterisks (`*`) that are not intended to be parameters or wildcards, they must be escaped with a backslash (`\`).
fix
For literal characters, use `\:` for a colon and `\*` for an asterisk. For example, `/static\:path/`.
affects: >=0.7.12
Errors
Common errors & fixes
TypeError: addRoute is not a function
Attempting to use `addRoute` without correctly importing it from an ESM module, likely in a CommonJS context or with incorrect import syntax.
fix
Ensure you are using `import { addRoute } from 'rou3';` in an ESM environment, or configure your bundler (like Webpack/Rollup/esbuild) to correctly handle ESM modules in a CommonJS project.
Router does not match expected path/method combinations, returns `undefined`
Common causes include paths not starting with `/`, methods not being uppercase, or incorrect URL pattern syntax, especially after v0.8.0 compatibility changes.
fix
Verify that all paths start with `/` and all methods are uppercase. Check your route patterns against the URLPattern compatibility documentation, particularly for complex regex or wildcard usage.
Upgrade
Version history
0.8.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
rou3 — npm install rou3 · libregistry