{"id":17248,"library":"healthpoint","title":"healthpoint - HTTP Server Health Check","description":"healthpoint is a lightweight Node.js utility designed to simplify the exposure of an HTTP server's health status. It provides a straightforward function that returns an HTTP request handler, allowing developers to easily integrate health check endpoints into their applications. The package, currently stable at version 1.0.0, operates on a `require`-based CommonJS module system, indicating a focus on compatibility with established Node.js environments. Its release cadence is likely slow or non-existent, given its simple, self-contained functionality. Key differentiators include its minimal API, ease of integration into existing `http` servers, and the ability to customize both the static properties exposed in the health check JSON and a dynamic asynchronous `check` function for custom health logic (e.g., database connectivity). Unlike more complex monitoring agents, healthpoint provides a focused, on-demand health status report directly from the application.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/davidguttman/healthpoint","tags":["javascript","health","check","http","uptime"],"install":[{"cmd":"npm install healthpoint","lang":"bash","label":"npm"},{"cmd":"yarn add healthpoint","lang":"bash","label":"yarn"},{"cmd":"pnpm add healthpoint","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only (uses `require`). Direct `import` syntax will not work in pure ESM environments without a CommonJS wrapper or bundler.","wrong":"import healthpoint from 'healthpoint'","symbol":"healthpoint","correct":"const healthpoint = require('healthpoint')"}],"quickstart":{"code":"const http = require('http');\nconst healthpoint = require('healthpoint');\n\n// Create a healthpoint handler\n// It exposes 'version' and runs a custom check function\nconst hp = healthpoint({\n  version: '1.0.0', // Replace with dynamic version from package.json\n  serviceName: 'MyWebApp'\n}, function (cb) {\n  // In a real application, you would check database connections,\n  // external APIs, or other critical services here.\n  // For demonstration, we'll alternate between healthy and unhealthy every 5 seconds.\n  const isOk = Math.round(Date.now() / 5000) % 2;\n  if (isOk) {\n    cb(null); // Healthy\n  } else {\n    cb(new Error('Database connection failed or external service unreachable.')); // Unhealthy\n  }\n});\n\n// Create a simple HTTP server\nconst server = http.createServer(function (req, res) {\n  if (req.url === '/health') {\n    // Delegate health check requests to the healthpoint handler\n    return hp(req, res);\n  }\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('Visit /health for the health check endpoint');\n});\n\nserver.listen(1337, () => {\n  console.log('Server running at http://localhost:1337');\n  console.log('Visit http://localhost:1337/health for the health check');\n});","lang":"javascript","description":"Demonstrates how to set up an HTTP server, integrate `healthpoint` as a middleware for the `/health` endpoint, and implement a custom asynchronous health check function."},"warnings":[{"fix":"Use `const healthpoint = require('healthpoint');` in CommonJS modules. For ESM projects, you might need to use a CommonJS wrapper, dynamic `import()` if Node.js version supports it, or a bundling tool that handles CommonJS modules.","message":"The `healthpoint` package is exclusively CommonJS (`require`) and does not natively support ECMAScript Modules (`import`). Attempting to `import` it directly in a pure ESM environment will lead to errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your custom `check` function always invokes the provided `cb` callback. Call `cb(null)` for a healthy state and `cb(new Error('message'))` for an unhealthy state.","message":"The custom health check function provided to `healthpoint` expects a Node.js-style callback (`cb(err, result)`). Developers accustomed to Promises or `async/await` might incorrectly return a Promise or omit calling the callback, leading to unresponsive or incorrect health statuses.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are using `const healthpoint = require('healthpoint');` in a CommonJS module context. If in an ESM project, consider using dynamic `import()` if your Node.js version supports it for CJS modules, or check if a transpiler is configured to handle CJS.","cause":"Attempting to `import healthpoint from 'healthpoint'` in an ESM module, or incorrect CommonJS `require` syntax.","error":"TypeError: healthpoint is not a function"},{"fix":"Verify that your asynchronous `check` logic consistently calls `cb(null)` for success or `cb(new Error('reason'))` for failure. Every code path within your `check` function must eventually invoke the callback.","cause":"The custom `check` function passed to `healthpoint` is not calling its `callback` argument, preventing the health check response from being sent.","error":"Health check endpoint hangs or always returns pending status."}],"ecosystem":"npm","meta_description":null}