Fastify core concepts
Second chapter of the "Fastify with TypeScript" series. Before jumping into project setup, let's build a mental map of how Fastify is actually put together. Everything you'll build in the rest of this series — routes, plugins, authentication, database access — is a combination of five core building blocks, and every later chapter is really just a deep dive into one of them.
We'll go through the five ideas first, then run one small file that uses all of them.
1. The Fastify instance
Everything starts from a single call to Fastify() , which returns an instance exposing a small API: .get() , .post() , .register() , .decorate() , .addHook() , and so on.
const app = Fastify ( { logger : true } ) ;
Enter fullscreen mode
Exit fullscreen mode
That instance is passed down through every plugin you register, which is why so much of Fastify's API is designed around receiving fastify as a function parameter rather than importing a global singleton — this is what makes testing and dependency…