API Reference

Fastify

High-performance Node.js web framework with schema-based validation, low overhead, and an extensible plugin architecture.

Official Documentation ↗
CompatibilityThis documentation covers version v4.27. Check the official docs for the latest API surface.

Installation

npmnpm install fastify
pnpmpnpm add fastify
yarnyarn add fastify

Methods

Fastify is a web framework highly focused on performance and developer experience. It offers an extensible plugin architecture, schema-based serialization and validation, and detailed logging out of the box.

Key Features

  • High throughput: Up to 2-3x faster than Express on JSON workloads
  • Schema validation: Compile-time JSON Schema for inputs and outputs
  • Plugin encapsulation: Scoped decorators, hooks, and routes per plugin
  • Hooks: Lifecycle events from onRequest to onResponse and onError
  • TypeScript support: First-class types and JSON Schema generation

FAQ

Why is Fastify faster than Express?
Fastify uses a radix-tree router, JSON Schema-based serialization via fast-json-stringify, and avoids middleware overhead. Benchmarks show 2-3x higher throughput than Express for JSON APIs.
How does schema validation work in Fastify?
You declare JSON Schema for params, querystring, body, and response on each route. Fastify compiles them with Ajv at boot, validating input and serializing output for speed and safety.
Can I use Express middleware with Fastify?
Not directly. Use @fastify/express to mount Express middleware, but prefer Fastify plugins and hooks for native performance. Many Express patterns have Fastify equivalents.