Routinejs, An Express는 놀랍도록 빠른 Nodejs 라우터에 영감을 주었습니다.
Express에서 영감을 받아 호환되는 Nodejs 라우터인 Routine을 소개하려고 합니다.
Documentation is still a work in progress but the core framework api is stable and ready to use.
Please consider leaving a star at Routine's Github repo
루틴의 일부 고급 기능
✅ Express보다 4배 빠릅니다(벤치마크 코드도 레포 내에서 사용 가능)
✅ Typescript 지원이 내장되어 있습니다.
✅ 정규식을 URL 경로로 지원
✅ 글로벌 동기화/비동기 오류 핸들러
✅ 미들웨어 및 중첩 경로 지원
✅ 거의 모든 기존 Expressjs 플러그인/미들웨어 지원
✅ 내장 바디 파서
✅ 기본 JSON.stringify보다 빠르고 순환 객체도 감지하는 fast-safe-stringify를 사용하여 json 응답자 내장
Benchmark comparing
RoutinewithExpressandHapi,Koawas also tested but it failed to process so many requests and kept givingERPIPE error, You can run these benchmarks yourself as well, simply refer to thebenchmarksfolder within the repo

Code examples below are also available on CodeSandbox here
Typescript의 간단한 Hello World 예제부터 시작하겠습니다.
//Importing Routine class along with some types
import Routine, { Request, Response } from "@juniordev/routinejs";
//Creating a new instance of Routine
const app = new Routine();
//Registering a GET route on path '/'
app.get(`/`, (req: Request, res: Response) => {
res.json({
msg: "Hello Routine"
});
});
//Starting the server on PORT 8080, default port is also 8080
app.listen(8080);
그러면
http://localhost:8080에서 서버가 시작되고 이 URL을 방문하면 {"msg": "Hello Routine"} 경로에 등록된 GET 경로가 있으므로 /를 수신합니다.Note: The built-in
.jsonmethod usesfast-safe-stringifywhich is faster than nativeJSON.stringifyand also detects and prevents[Circular]Object within Response, So it is highly recommended to use this method for sending json payload to client.
POST 경로를 살펴보겠습니다.
//Importing Routine class along with some types
import Routine, { Request, Response } from "@juniordev/routinejs";
//Creating a new instance of Routine
const app = new Routine();
//Registering a GET route on path '/'
app.get(`/`, (req: Request, res: Response) => {
res.json({
msg: "Hello Routine"
});
});
//Registering a POST route also on path `/`
app.post(`/`, (req: Request, res: Response) => {
//Automatic request body parsing without any plugin
//Sending the request body back to the client
res.json(req.body);
});
//Starting the server on PORT 8080, default port is also 8080
app.listen(8080);
이번에는 서버에 본문으로 보내는 모든 것을 수신하고,
{"msg": "Hello Routine"}를 JSON 페이로드로 서버에 보내면 {"msg": "Hello Routine"}를 다시 받습니다.루틴에는 다음과 같은 모든 주요
http verbs 내장 기능이 있습니다.GET , POST , PUT , PATCH 및 DELETE명명된 및 쿼리 매개변수
//Importing Routine class along with some types
import Routine, { Request, Response } from "@juniordev/routinejs";
//Creating a new instance of Routine
const app = new Routine();
//Registering a GET route on path '/:name'
app.get(`/:name`, (req: Request, res: Response) => {
res.json({
name: req.params.name,
query: req.query
});
});
//Starting the server on PORT 8080, default port is also 8080
app.listen(8080);
방문
http://localhost:8080/routine?hello=world은 우리를 반환합니다.{
"name": "routine",
"query": {
"hello": "world"
}
}
Note: You can put any valid
regexas path and routine will try to match it
미들웨어 사용
//Registering a middleware
app.use((req: Request, res: Response, next: NextFunction) => {
console.log("middleware called");
next();
});
Middleware functionality is same as Express, that is why Routine is almost fully compatible with Express plugins, and is tested with popular ones such as
Morgan,Express Validatoretc
마지막으로
nested routes가 어떻게 구현되는지 살펴보겠습니다.//src/router.ts
import { Router, Request, Response } from "@juniordev/routinejs";
const router = new Router();
router.get(`/router`, (req: Request, res: Response) => {
res.json({
msg: "from router"
});
});
export default router;
//src/index.ts
import Routine, { NextFunction, Request, Response } from "@juniordev/routinejs";
import router from "./router";
//Creating a new instance of Routine
const app = new Routine();
//Using a nested router
app.use(`/nested`, router);
app.listen(8080)
http://localhost:8080/nested/router를 방문하면 서버가 {"msg":"from router"}를 반환합니다.All the above
http methods,named or query params,middlewarescan also be applied tonested routesas well, even so much so thatnested routescan have morenested routes, and it does NOT degrade route matching performance due to startup/compile time route compilation
이것은
Routine에 대한 기본 소개였습니다. cancel 기능, global async error handling 등과 같은 많은 기능은 아직 언급되지 않았지만 향후 게시물에서 다룰 예정입니다. async 오류 처리에 대한 docs을 읽을 수 있습니다. 하지만 지금은 주의할 점, 좋은 읽기 약속합니다 :)
Reference
이 문제에 관하여(Routinejs, An Express는 놀랍도록 빠른 Nodejs 라우터에 영감을 주었습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/zulfiqarqureshi/routinejs-an-express-inspired-blazingly-fast-nodejs-router-3hpg텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)