Lesson 23 / 30
Deployment & Production
Take Fastify to production with best practices.
Production checklist
Set NODE_ENV=production, use environment variables for secrets, add health checks, enable HTTPS, and use a reverse proxy.
Health check endpoint
A simple health check route for load balancers to monitor your app.
fastify.get('/health', async () => {
return {
status: 'ok',
uptime: process.uptime(),
timestamp: new Date().toISOString(),
};
});
fastify.get('/ready', async () => {
// Check database connectivity, external services, etc.
try {
await fastify.db.query('SELECT 1');
return { ready: true };
} catch {
return reply.status(503).send({ ready: false });
}
});