Backend2024년 12월 6일2분 읽기

Fastify — Node.js 고성능 웹 프레임워크

YS
YoungSam
조회 416

왜 Fastify인가

Fastify는 Express 대비 약 2~3배 빠른 처리 성능을 제공합니다. JSON Schema 기반 검증과 직렬화가 핵심입니다.

스키마 기반 라우트

import Fastify from "fastify";
const app = Fastify({ logger: true });

app.post("/users", {
  schema: {
    body: {
      type: "object",
      required: ["name", "email"],
      properties: {
        name: { type: "string" },
        email: { type: "string", format: "email" },
      },
    },
  },
  handler: async (req, reply) => {
    const user = await createUser(req.body);
    return reply.code(201).send(user);
  },
});
FastifyNode.jsAPI

댓글 0

아직 댓글이 없습니다.