Lesson 25 / 32

Deployment & Production

Prepare Fastify for production with NODE_ENV, environment secrets, health checks and HTTPS.

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 });
  }
});