Fastify is a high-performance web framework for Node.js designed with developer experience and minimal overhead as core principles. Built from the ground up with performance in mind, it leverages a powerful plugin architecture, JSON Schema-based validation, and schema-driven serialization to deliver throughput rates 2-4× faster than Express. The framework's encapsulation model ensures that decorators, hooks, and plugins remain isolated within their registration context, preventing unintended side effects across application boundaries. A critical mental model: Fastify compiles JSON schemas at startup into highly optimized functions, meaning validation and serialization happen at near-native speed rather than runtime interpretation cost typical of other frameworks.
What This Cheat Sheet Covers
This topic spans 24 focused tables and 196 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Server Initialization and Configuration
| Option | Example | Description |
|---|---|---|
fastify({ logger: true }) | • Enables Pino logger with default 'info' level • accepts boolean or config object with level, stream, and serializers | |
fastify({ bodyLimit: 2097152 }) | • Sets maximum request body size in bytes • defaults to 1048576 (1 MiB) to prevent memory exhaustion | |
fastify({ trustProxy: true }) | • Enables proxied headers like X-Forwarded-For • required for accurate client IP behind load balancers or reverse proxies | |
fastify({ ignoreTrailingSlash: true }) | • Treats /users and /users/ as same route• simplifies routing logic by normalizing URL patterns | |
fastify({ caseSensitive: false }) | • Makes route paths case-insensitive • treats /Users and /users as identical routes | |
fastify({ requestIdHeader: 'x-request-id' }) | • Reads existing request ID from header • useful for distributed tracing across microservices |