Fastify From Zero
Learn the fast, schema-first Node.js framework: routing with JSON-schema validation and serialization, the encapsulated plugin system, the request/reply lifecycle and hooks, building a REST API, error handling, and testing and production. A modern, performance-focused alternative to Express that bakes in validation and structure.
- What Fastify Is & Your First Server Fastify is the fast, schema-first Node.js framework — an Express alternative with validation built in. Install it, write a tiny async server, run it, and meet the two ideas that define it.
- Routing & Schemas Routing in Fastify by method, params, query, and body — and attaching a JSON Schema to a route so Fastify validates input and fast-serializes output for you, no validation code required.
- The Plugin System How Fastify organizes apps as a tree of encapsulated plugins: writing a plugin, registering it with a prefix, decorating the instance, and using fastify-plugin to share across the whole app.
- Hooks & the Lifecycle Every request flows through a named request/reply lifecycle. Hooks let you run code at each stage — onRequest, preHandler, onSend — and they respect plugin encapsulation, so you can guard one route group cleanly.
- Building a REST API Assemble routing, schemas, plugins, and hooks into a full books CRUD API: five schema-backed routes in one encapsulated plugin over an in-memory collection, with tiny handlers because validation lives in the schema.
- Error Handling How Fastify makes most error handling automatic — schema-validation 400s and auto-caught async throws — and how one setErrorHandler, typed errors, and setNotFoundHandler shape the rest into consistent responses.
- Testing & Production Test the books API in process with Fastify's built-in app.inject(), structure the app as a buildApp() function, then harden for production with pino logging, graceful shutdown, env config, and official plugins.
- Where to Go Next What you can build now, how Fastify compares to Express, NestJS, and bare node:http, the @fastify/* plugin ecosystem, TypeScript type providers, and one concrete thing to go build.