Menu

Production deployment — Fastify with TypeScript (part 18/18)
📰

Production deployment — Fastify with TypeScript (part 18/18)

DEV Community: fastify·Antonio Tripodi·6 days ago
#58yQ5MF4
#devtofastify#devto#dev#node#health
Long article (1644 words) — no AI summary yet.
Reading 0:00
15s threshold

Production deployment

Eighteenth and final chapter of the "Fastify with TypeScript" series. Let's close the loop: graceful shutdown, health checks for your orchestrator, a production-ready Dockerfile, and a look back at the principles the whole series has been following.

Graceful shutdown

When Kubernetes (or docker stop , or a Ctrl-C) sends SIGTERM , you want to stop accepting new connections, let the requests in flight finish, close the database pool, and only then exit. close-with-grace wires the signals to app.close() , and forcibly exits if that takes too long:

npm install close-with-grace

Enter fullscreen mode

Exit fullscreen mode

Replace src/server.ts with:

// src/server.ts import closeWithGrace from 'close-with-grace' ; import { buildApp } from './app.ts' ;

const app = buildApp ( ) ;

closeWithGrace ( { delay : 10_000 } , async ( { signal , err } ) => { if ( err ) { app . log . error ( { err } , 'Shutting down due to an error' ) ; } else { app . log .…

Continue reading — create a free account

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