Introducing @saahen.sriyan.mishra/micro-router

No more bloated dependencies just to set up a simple HTTP router in Node.js.
@saahen.sriyan.mishra/micro-router, a secure, lightweight, and zero-dependency routing package built with simplicity, speed, and security in mind — perfect for microservices, internal tools, or quick prototyping.


Installation

npm install @saahen.sriyan.mishra/micro-router

Core Features

  • Register GET/POST/PUT/DELETE routes
  • Built-in rate limiting
  • Secure headers out-of-the-box
  • Auto IP blacklisting
  • Request logging
  • JSON payload validation
  • Payload size limit (1MB)

Folder Structure Overview

micro-router/
├── index.js          # Core router logic
├── test.js           # Server boot example
├── run-tests.js      # CLI-based endpoint test runner
├── .npmrc            # Custom NPM config
├── package.json      # Package metadata
└── README.md         # Documentation
└── Test.md           # Test Report Documentation

🧪 Example Usage

const MicroRouter = require("@saahen.sriyan.mishra/micro-router");
const router = new MicroRouter();

router.register("GET", "/public", (req, res) => {
  res.writeHead(200, { "Content-Type": "application/json" });
  res.end(JSON.stringify({ message: "Public Access!" }));
});

router.register("POST", "/post-data", (req, res) => {
  res.writeHead(200, { "Content-Type": "application/json" });
  res.end(JSON.stringify({ message: "Payload Received", data: req.body }));
});

router.register("GET", "/admin", (req, res) => {
  res.writeHead(200, { "Content-Type": "application/json" });
  res.end(JSON.stringify({ message: "Admin Access!" }));
});

router.listen(4000);

📌 API Methods

Method Description
router.register() Register a route (GET, POST, PUT, DELETE)
router.listen() Start the HTTP server
router.blockIP() Block an IP address (blacklist)
router.allowIP() Remove IP from blacklist
router.showLogs() Print request logs with IP, time, and route
router.middleware() Internal security & rate limit checks
router.validatePayload() Auto-invoked for POST/PUT to parse JSON & prevent large payloads
router.handler() Main route resolver with validation, protection, and dispatch
router.normalizeIP() Handles IPv6/local address translation

Test Automation

The included run-tests.js script runs:

  • GET on /public
  • POST on /post-data with JSON payload
  • 7x requests to /admin to test rate limiting
  • Header inspection for secure headers
  • Simulated IP blocking & denial
npm run test

Output will display success & error states, proving the built-in protections work.


Built-in Security

  • Rate limit: 5 requests / 5 seconds / IP
  • Auto-block after 10 suspicious attempts
  • Headers: X-Content-Type-Options, X-Frame-Options, Content-Security-Policy
  • JSON size limit: 1MB

Why Use This?

🔹 Need something smaller than Express

🔹 Want out-of-the-box security

🔹 Avoid installing extra middleware

🔹 Build REST services without clutter


Learn More


👨‍💻 Author

Saahen Sriyan Mishra

Creating secure, simple tools for fast Node.js development.

🔗 GitHub: @saahen-sriyan-mishra


Final Thoughts

If you're building fast and care about performance, clarity, and security — this router has your back. Try it out.

npm install @saahen.sriyan.mishra/micro-router