Menu

Your first server (app.ts, server.ts, config.ts) — Fastify with TypeScript (part 4/18)
📰

Your first server (app.ts, server.ts, config.ts) — Fastify with TypeScript (part 4/18)

DEV Community: fastify·Antonio Tripodi·11 days ago
#E2HVKdCX
#devtofastify#devto#dev#config#type
Long article (1042 words) — no AI summary yet.
Reading 0:00
15s threshold

Your first server (app.ts, server.ts, config.ts)

Fourth chapter of the "Fastify with TypeScript" series. Let's build our first server following a widely-used convention from the start: the app build step ( app.ts ) is separated from the server startup step ( server.ts ), and configuration comes from environment variables validated against a schema ( config.ts ).

We continue in the my-fastify-app project from the previous chapter. The three files below replace the temporary src/server.ts we used to test the setup.

config.ts — typed configuration

Almost every later chapter needs a value from the environment: a database URL, a JWT secret, a port. Reading process.env.X directly gives you string | undefined everywhere and fails silently when a variable is missing.…

Continue reading — create a free account

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