https://github.com/saahen-sriyan-mishra/npm-micro-router-package
A lightweight, high-performance HTTP routing library for Node.js, designode.js, designed for simplicity and speed without external dependencies.
https://github.com/saahen-sriyan-mishra/npm-micro-router-package
Last synced: 26 days ago
JSON representation
A lightweight, high-performance HTTP routing library for Node.js, designode.js, designed for simplicity and speed without external dependencies.
- Host: GitHub
- URL: https://github.com/saahen-sriyan-mishra/npm-micro-router-package
- Owner: saahen-sriyan-mishra
- Created: 2025-05-02T17:54:04.000Z (about 1 month ago)
- Default Branch: master
- Last Pushed: 2025-05-02T18:36:39.000Z (about 1 month ago)
- Last Synced: 2025-05-02T18:42:29.123Z (about 1 month ago)
- Language: JavaScript
- Size: 0 Bytes
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# @saahen.sriyan.mishra/micro-router
A lightweight, dependency-free, and secure HTTP router for Node.js that provides essential routing capabilities combined with built-in security, logging, and rate limiting — perfect for microservices, internal tools, or fast prototyping.
---
## Installation```bash
npm install @saahen.sriyan.mishra/micro-router
```## Usages
**Import**
``` JavaScript
const MicroRouter = require("@saahen.sriyan.mishra/micro-router");
const router = new MicroRouter();
```| Method | Parameters | Description | Automates / Simplifies |
| -------------------------- | ------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------- |
| `router.register()` | `(method, path, handler)` | Registers a new route (GET, POST, PUT, DELETE) | Avoids writing custom route handling logic |
| `router.listen()` | `(port = 3000)` | Starts the HTTP server and listens on the given port | Bootstraps server with built-in security |
| `router.blockIP()` | `(ip)` | Adds an IP address to the internal blacklist | Manual firewall-like control |
| `router.allowIP()` | `(ip)` | Removes an IP from the blacklist | Grants access back to blocked IPs |
| `router.showLogs()` | `()` | Displays the internal request logs with timestamp, method, and IP | Makes auditing/debugging easier |
| *Built-in Middleware* | (internal, auto-invoked) | Applies security headers, rate-limiting, JSON validation, payload size limiting automatically | No need for separate middlewares |
| `router.validatePayload()` | `(req, res, callback)` | Parses and validates JSON for POST/PUT requests (called automatically) | Prevents invalid or oversized JSON manually |
| `router.middleware()` | `(req, res)` | Checks for blacklists, rate limits, secure headers (auto-used in `.handler()`) | Handles security policies out-of-the-box |
| `router.handler()` | `(req, res)` | Internal routing logic that invokes correct route handlers (auto-used in `.listen()`) | Complete route + validation logic |
| `router.normalizeIP()` | `(ip)` | Standardizes local and remote IP formats | Handles localhost vs real IP equivalence |