Stone.js router for both Node.js and browser environments, designed for serverless applications.
Stone Router is a high-performance, universal router designed to work seamlessly across Node.js and browser environments. As a core part of the Stone.js framework, it enables robust, declarative, and composable route handling for serverless, SSR, and SPA applications.
- Universal: Works on both backend and frontend (Node.js, browsers, SSR apps).
- Composable: Supports route builders, chaining, and nested route structures.
- Context-Aware: Routes are designed to respond to the execution context.
- Type-Safe & Declarative: Built with TypeScript-first principles.
- Fast & Lightweight: Optimized for high-performance and minimal overhead.
- Model Binding: Automatically inject models and bindings into routes.
- Flexible Middleware System: Apply middleware globally or per route.
- Regex and Dynamic Params: Advanced matching for custom use cases.
- Error Handling & Fallbacks: Integrated with the event lifecycle.
- Smart Defaults: Supports defaults, route rules, redirect handling, etc.
npm install @stone-js/router
Important
This package is pure ESM. Ensure your package.json
includes "type": "module"
or configure your bundler appropriately.
Stone Router exposes a functional/declarative API that allows defining, composing, and dispatching routes easily.
It is designed to be used in both server and client contexts, making it ideal for modern web applications that require a unified routing solution.
It fully integrates with the event system of Stone.js through IncomingEvent
and OutgoingResponse
.
import { IncomingEvent } from '@stone-js/core'
import { defineRoutes } from '@stone-js/router'
export const routes = defineRoutes([
{
method: 'GET',
path: '/users/:id',
handler: async (event: IncomingEvent) => {
return { body: `User ID: ${event.get('id') }` }
}
}
])
This package is part of the Stone.js ecosystem, a modern JavaScript framework built around the Continuum Architecture.
Explore the full documentation: https://stonejs.dev