httprouter-js
v1.0.4
Published
Super fast web router for node.js
Downloads
2
Readme
HttpRouter
Super fast web router for node.js, rewritten from golang's httprouter
Installation
npm i httprouter-js -S
Usage
import { createServer, IncomingMessage, ServerResponse } from "http";
import { Router } from "httprouter-js";
const router = new Router();
function Index(res: ServerResponse, req: IncomingMessage, params: any) {
res.write(
"Welcome! " +
(params ? params.find((v: any) => v.Key === "name").Value : "")
);
res.end();
}
router.GET("/another", Index);
router.GET("/hello/:name", Index);
const server = createServer(router.ServeHTTP.bind(router));
server.listen(3000);
console.log("Listening on 3000..");
Todo
- [ ] middleware
- [ ] adapter for express or koa
License
MIT