{"library":"server-health","title":"Server Health Endpoint","description":"The `server-health` library provides a standardized `/health` HTTP endpoint for various Node.js web frameworks, including Express, Fastify, Restify, Hapi, and vanilla HTTP servers. It offers vital service information such as overall status, uptime, package metadata (name, description, version, repository), environment details (nodeEnv, nodeVersion, pid, cwd), git commit information, and allows for pluggable custom connection checks (e.g., database, message queues). The current stable version is `7.0.0`, which primarily targets Node.js `v20.0.0` or higher, having dropped support for Node.js v18 and specific Restify versions on newer Node environments. The library focuses on providing a detailed, extensible health check solution without imposing a specific framework, making it highly adaptable. Key differentiators include server-side response filtering for specific data points and a comprehensive set of diagnostic data provided by default.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install server-health"],"cli":null},"imports":["import serverHealth from 'server-health'; // For ESM environments","import serverHealth from 'server-health';\nserverHealth.addConnectionCheck('db', () => true);","import serverHealth from 'server-health';\nserverHealth.exposeHealthEndpoint(server, '/health', 'fastify');","import serverHealth from 'server-health';\nconst nodeServer = serverHealth.createNodeHttpHealthCheckServer({});"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import serverHealth from 'server-health';\nimport fastify from 'fastify';\n\n// Add custom connection checks\nserverHealth.addConnectionCheck('database', function () {\n  // In a real application, this would check actual database connectivity.\n  // For this example, we'll simulate a healthy connection.\n  return true; \n});\nserverHealth.addConnectionCheck('redis', function () {\n  // Simulate a healthy Redis connection\n  return true;\n});\n\nconst server = fastify();\n\n// Expose the health endpoint on the Fastify server\nserverHealth.exposeHealthEndpoint(server, '/health', 'fastify');\n\nconst PORT = process.env.PORT ?? 8080;\n\nserver.listen({ port: PORT }, (err) => {\n  if (err) {\n    server.log.error(err);\n    process.exit(1);\n  }\n  console.log(`Server listening on http://localhost:${PORT}`);\n  console.log(`Health endpoint available at http://localhost:${PORT}/health`);\n});","lang":"typescript","description":"Demonstrates initializing `server-health` with a Fastify server, adding custom connection checks, and exposing the `/health` endpoint.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}