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.…