rustling-river-routes
v1.1.5
Published
A lightweight routing library for node.js applications.
Downloads
8
Maintainers
Readme
Rustling River Routes
A lightweight routing library for Node.js applications, inspired by the simplicity and flexibility of Express.js but tailored for smaller scale projects.
Features
- Simple API for route handling.
- Supports dynamic route parameters.
- Query string parsing.
- Lightweight with minimal dependencies.
Installation
npm install rustling-river-routes
Usage
Initialize your router and define routes like so:
const RustlingRiverRoutes = require('rustling-river-routes');
const http = require('http');
const router = new RustlingRiverRoutes();
router.add('/user/:id', (req, res, params) => {
res.end(`User ID: \${params.id}`);
});
const server = http.createServer((req, res) => {
router.handle(req, res);
});
server.listen(3000, () => {
console.log('Server listening on port 3000');
});
Handling 404 Not Found
Rustling River Routes emits an 'error' event for handling 404 errors or other types of exceptions:
router.on('error', (error, req, res) => {
res.statusCode = error.status || 500;
res.end(error.message);
});
License
This project is licensed under the MIT License.