app.close()
Gracefully shuts down the server, running onClose hooks.
Syntax
app.close(): Promise<void> Returns
Promise<void> — Resolves when the server and plugins have closed.
Examples
import Fastify from 'fastify';
const app = Fastify();
await app.listen({ port: 3000 });
for (const signal of ['SIGINT', 'SIGTERM'] as const) {
process.on(signal, async () => {
await app.close();
process.exit(0);
});
}
Notes
close() stops accepting new connections and runs every onClose hook so
plugins can release resources (DB pools, timers). Pair it with a process
signal handler for graceful shutdown.