# Fastify best practices > Use when building, configuring or debugging a Fastify server or REST API. Guides development of Fastify Node.js backend servers and REST APIs using TypeScript or JavaScript. Use when building, configuring, or debugging a Fastify application — including defining routes, implementing plugins, setting up JSON Schema validation, handling errors, optimising performance, managing authentication, configuring CORS and security headers, integrating databases, working with WebSockets, and deploying to production. Covers the full Fastify request lifecycle (hooks, serialization, logging with Pino) and TypeScript integration via strip types. Trigger terms: Fastify, Node.js server, REST API, API routes, backend framework, fastify.config, server.ts, app.ts. ## Facts - Type: Agent skill - Discipline: Engineering - Author: Matteo Collina (https://github.com/mcollina) - Upstream: https://github.com/mcollina/skills/blob/main/skills/fastify/SKILL.md - Source file: https://raw.githubusercontent.com/mcollina/skills/main/skills/fastify/SKILL.md (3775 bytes, sha256:d1d90340de01fe4b13aadcc868e69a15f98bf03d1dd881bacbb4762b93e93733) - Licence: MIT - Upstream copy last changed: 2026-09-17 - Status: listed, not yet ruled on by the curator ## Use it I want to use the Fastify best practices skill by Matteo Collina. This is what it does, in the author's own words: Guides development of Fastify Node.js backend servers and REST APIs using TypeScript or JavaScript. Use when building, configuring, or debugging a Fastify application — including defining routes, implementing plugins, setting up JSON Schema validation, handling errors, optimising performance, managing authentication, configuring CORS and security headers, integrating databases, working with WebSockets, and deploying to production. Covers the full Fastify request lifecycle (hooks, serialization, logging with Pino) and TypeScript integration via strip types. Trigger terms: Fastify, Node.js server, REST API, API routes, backend framework, fastify.config, server.ts, app.ts. Download the whole folder at https://github.com/mcollina/skills/tree/main/skills/fastify, SKILL.md and every file beside it, into your skills directory: ~/.claude/skills/fastify-best-practices/ for Claude Code, ~/.agents/skills/fastify-best-practices/ for Codex, ~/.cursor/skills/fastify-best-practices/ for Cursor. Get it from the author's repo, not from startupskills.dev. Then tell me the path you installed it to and how to invoke it. Nothing here is vendored: install from the author's repo, not from this site. A verbatim copy of the author's file follows for reading, under the licence reproduced after it; the current file is in the author's repo. ## Links - Page: https://startupskills.dev/mcollina/fastify-best-practices - Author: https://startupskills.dev/mcollina - Index: https://startupskills.dev/llms.txt ## The file itself --- name: fastify-best-practices description: "Guides development of Fastify Node.js backend servers and REST APIs using TypeScript or JavaScript. Use when building, configuring, or debugging a Fastify application — including defining routes, implementing plugins, setting up JSON Schema validation, handling errors, optimising performance, managing authentication, configuring CORS and security headers, integrating databases, working with WebSockets, and deploying to production. Covers the full Fastify request lifecycle (hooks, serialization, logging with Pino) and TypeScript integration via strip types. Trigger terms: Fastify, Node.js server, REST API, API routes, backend framework, fastify.config, server.ts, app.ts." metadata: tags: fastify, nodejs, typescript, backend, api, server, http --- ## When to use Use this skill when you need to: - Develop backend applications using Fastify - Implement Fastify plugins and route handlers - Get guidance on Fastify architecture and patterns - Use TypeScript with Fastify (strip types) - Implement testing with Fastify's inject method - Configure validation, serialization, and error handling ## Quick Start A minimal, runnable Fastify server to get started immediately: ```ts import Fastify from 'fastify' const app = Fastify({ logger: true }) app.get('/health', async (request, reply) => { return { status: 'ok' } }) const start = async () => { await app.listen({ port: 3000, host: '0.0.0.0' }) } start() ``` ## Recommended Reading Order for Common Scenarios - **New to Fastify?** Start with `plugins.md` → `routes.md` → `schemas.md` - **Adding authentication:** `plugins.md` → `hooks.md` → `authentication.md` - **Improving performance:** `schemas.md` → `serialization.md` → `performance.md` - **Setting up testing:** `routes.md` → `testing.md` - **Going to production:** `logging.md` → `configuration.md` → `deployment.md` ## How to use Read individual rule files for detailed explanations and code examples: - [rules/plugins.md](rules/plugins.md) - Plugin development and encapsulation - [rules/routes.md](rules/routes.md) - Route organization and handlers - [rules/schemas.md](rules/schemas.md) - JSON Schema validation - [rules/error-handling.md](rules/error-handling.md) - Error handling patterns - [rules/hooks.md](rules/hooks.md) - Hooks and request lifecycle - [rules/authentication.md](rules/authentication.md) - Authentication and authorization - [rules/testing.md](rules/testing.md) - Testing with inject() - [rules/performance.md](rules/performance.md) - Performance optimization - [rules/logging.md](rules/logging.md) - Logging with Pino - [rules/typescript.md](rules/typescript.md) - TypeScript integration - [rules/decorators.md](rules/decorators.md) - Decorators and extensions - [rules/content-type.md](rules/content-type.md) - Content type parsing - [rules/serialization.md](rules/serialization.md) - Response serialization - [rules/cors-security.md](rules/cors-security.md) - CORS and security headers - [rules/websockets.md](rules/websockets.md) - WebSocket support - [rules/database.md](rules/database.md) - Database integration patterns - [rules/configuration.md](rules/configuration.md) - Application configuration - [rules/deployment.md](rules/deployment.md) - Production deployment - [rules/http-proxy.md](rules/http-proxy.md) - HTTP proxying and reply.from() ## Core Principles - **Encapsulation**: Fastify's plugin system provides automatic encapsulation - **Schema-first**: Define schemas for validation and serialization - **Performance**: Fastify is optimized for speed; use its features correctly - **Async/await**: All handlers and hooks support async functions - **Minimal dependencies**: Prefer Fastify's built-in features and official plugins ## Licence of the file above The file above is https://raw.githubusercontent.com/mcollina/skills/main/skills/fastify/SKILL.md, by Matteo Collina, reproduced without changes. - Source: https://github.com/mcollina/skills/blob/main/skills/fastify/SKILL.md - Copyright: Copyright (c) 2026 Matteo Collina - Licence: MIT, https://raw.githubusercontent.com/mcollina/skills/main/LICENSE The repo's licence file, verbatim from https://raw.githubusercontent.com/mcollina/skills/main/LICENSE: MIT License Copyright (c) 2026 Matteo Collina Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.