基于 Node.js 的轻量级 HTTP 路由模块
http-smpl-router
模块提供了一种简单高效的方式来处理 Node.js 中的 HTTP 路由。
安装
npm install http-smpl-router
使用方法
以下代码展示了如何使用 http-smpl-router
模块注册 GET 路由并处理请求:
const http = require('http');
const router = require('http-smpl-router');
http.createServer((req, resp) => {
router.route(req, resp);
}).listen(3000);
router.get('/helloworld', (req, resp) => {
resp.end("Hello World!!");
});
访问 http://localhost:3000/helloworld
即可查看结果。
http-smpl-router
模块支持 GET、POST、PUT、DELETE 等 HTTP 方法,您可以根据需要注册相应的路由。
2.81KB
文件大小:
评论区