Menu

Fastify core concepts — Fastify with TypeScript (part 2/18)
📰

Fastify core concepts — Fastify with TypeScript (part 2/18)

DEV Community: fastify·Antonio Tripodi·about 4 hours ago
#zypNkteb
#devtofastify#devto#dev#fastify#plugin
Long article (1100 words) — no AI summary yet.
Reading 0:00
15s threshold

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…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.