Cette page est affichée en anglais. Une traduction française est en cours.
SkillsApr 11, 2026·2 min de lecture

Fastify — Fast & Low Overhead Web Framework for Node.js

Fastify is a fast and low overhead web framework for Node.js, focused on providing the best developer experience with least overhead and a powerful plugin architecture. Schema-driven with JSON Schema validation built in.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
step-1.md
Commande d'installation directe
npx -y tokrepo@latest install 267271ae-355f-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

TL;DR
Fastify provides schema-driven validation and fast JSON serialization for Node.js APIs.
§01

What it is

Fastify is a web framework for Node.js focused on speed and low overhead. It uses JSON Schema for request validation and response serialization, achieving throughput that matches or exceeds other Node.js frameworks. The plugin architecture keeps code modular and testable. Built-in TypeScript support and automatic Swagger generation round out the developer experience.

This tool is for Node.js developers who need better performance than Express without sacrificing developer experience. It is especially suited for API-heavy applications where validation and serialization matter.

§02

How it saves time or tokens

Fastify's schema-driven approach validates inputs and serializes outputs automatically. Define a JSON Schema for your route, and Fastify rejects invalid requests before your handler runs, generates OpenAPI documentation, and serializes responses faster than JSON.stringify. The plugin system encourages reusable modules.

§03

How to use

  1. Install Fastify.
  2. Define routes with JSON Schema validation.
  3. Register plugins for functionality.
  4. Start the server.
# Create project
mkdir my-api && cd my-api
npm init -y
npm install fastify
§04

Example

const fastify = require('fastify')({ logger: true })

// Route with schema validation
fastify.post('/users', {
  schema: {
    body: {
      type: 'object',
      required: ['name', 'email'],
      properties: {
        name: { type: 'string', minLength: 1 },
        email: { type: 'string', format: 'email' }
      }
    },
    response: {
      201: {
        type: 'object',
        properties: {
          id: { type: 'string' },
          name: { type: 'string' },
          email: { type: 'string' }
        }
      }
    }
  }
}, async (request, reply) => {
  const user = {
    id: crypto.randomUUID(),
    ...request.body
  }
  return reply.code(201).send(user)
})

fastify.listen({ port: 3000 })

Invalid requests are rejected automatically with descriptive error messages.

§05

Related on TokRepo

§06

Common pitfalls

  • Fastify's plugin encapsulation can be confusing. Plugins registered in one scope are not available in another without proper decoration.
  • JSON Schema validation is strict by default. Properties not in the schema are stripped from requests. Set additionalProperties: true if you need them.
  • Response serialization requires accurate response schemas. Mismatched schemas cause serialization errors or data loss.
  • Fastify uses async/await natively. Callback-style code from Express needs refactoring.
  • The decorator pattern for dependency injection has a learning curve. Understand fastify.decorate() before building complex applications.
  • Review the official documentation before deploying to production to ensure compatibility with your specific environment and requirements.
  • Start with default settings and customize incrementally. Changing too many configuration options at once makes debugging harder.

Questions fréquentes

How fast is Fastify compared to Express?+

Fastify is typically 2-3x faster than Express in benchmarks for JSON response handling. The speed comes from fast JSON serialization via fast-json-stringify and efficient routing via find-my-way.

Does Fastify support TypeScript?+

Yes. Fastify has built-in TypeScript support with type-safe route definitions, plugin types, and schema inference. The types are maintained as part of the core package.

Can Fastify generate OpenAPI documentation?+

Yes. The @fastify/swagger plugin generates OpenAPI 3.0 documentation from your route schemas automatically. Add @fastify/swagger-ui for a browsable Swagger interface.

Is Fastify compatible with Express middleware?+

Not directly, but the @fastify/express plugin provides a compatibility layer. It lets you use Express middleware within Fastify, easing migration from Express.

How does the plugin system work?+

Fastify plugins are functions that receive the Fastify instance and options. They can add routes, decorators, hooks, and register sub-plugins. Encapsulation ensures plugins do not leak state into other parts of the application.

Sources citées (3)

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires