onReady hook

Runs once after all plugins have loaded but before the server starts listening.

Since Fastify 5 Spec ↗

Syntax

app.addHook('onReady', async () => {})

Returns

void | Promise<void> — Throwing prevents the server from starting.

Examples

import Fastify from 'fastify';

const app = Fastify();

app.addHook('onReady', async () => {
  await warmCache();
  app.log.info('cache warmed, ready to serve');
});

Notes

Application-level hook (no request arguments). Use it to verify dependencies or warm caches after boot. Throwing here aborts startup.