clear-router
v2.0.8
Published
Laravel-style routing system for Express.js and H3, with CommonJS, ESM, and TypeScript support
Maintainers
Readme
Toneflix Clear Router
Laravel-style routing system for Express.js in JavaScript. Clean route definitions, middleware support, and controller bindings with full TypeScript support.
Installation
npm install clear-router h3
# OR
npm install clear-router expressOR
pnpm add clear-router h3
# OR
pnpm add clear-router hexpress3OR
yarn add clear-router h3
# OR
yarn add clear-router expressFeatures
- Simple and clean route declarations (get, post, put, delete, patch, options, head)
- Grouped routes with prefix
- Middleware stack: per-route and group-level
- Controller-method pair as route handler
- Supports HttpContext style handlers: { req, res, next }
- Auto-binds controller methods
- Full CommonJS, ESM, and TypeScript support
- Error handling delegated to Express
- Route inspection with allRoutes method
- Fully Express-compatible
- Fully H3-compatible
Quick Start
Express JS
See the Express JS documentation for details.
H3
See the H3 documentation for details.
API Reference
See API.md for complete API documentation.
Error Handling
All errors during route execution are automatically passed to Express error handling middleware using next(error). You can define your error handler:
app.use((err, req, res, next) => {
console.error(err);
res.status(500).json({ error: err.message });
});Middleware Execution Order
[ Global Middleware ] → [ Group Middleware ] → [ Route Middleware ]Handler Execution
- If function: executed directly
- If [Controller, 'method']: auto-instantiated (if needed), method is called
Testing
npm test # Run all tests
npm run test:cjs # Test CommonJS
npm run test:esm # Test ESM
npm run test:ts # Test TypeScriptSee TESTING.md for detailed testing guide.
Examples
npm run example # CommonJS example
npm run example:esm # ESM example
npm run example:ts # TypeScript exampleCheck example/ directory for full working demos.
Changelog
See CHANGELOG.md for version history.
Requirements
- Node.js >= 14.0.0
- Express >= 5.0.0 | H3 >= 2.0.1
License
MIT License © 2026 ToneFlix Technologies Limited
Author
3m1n3nce [email protected]
Repository
https://github.com/toneflix/clear-router
