{"id":18411,"library":"healthcheck-middleware","title":"healthcheck-middleware","description":"An Express middleware for rendering a JSON healthcheck endpoint. v1.0.1 stable. Provides default health info (status, uptime, memory usage), supports custom checks via addChecks (promise-friendly) and custom health info formatting. Lightweight alternative to full monitoring libraries like node-monitor.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/michaelgoin/healthcheck-middleware","tags":["javascript","healthcheck","express","middleware","node","connect"],"install":[{"cmd":"npm install healthcheck-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add healthcheck-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add healthcheck-middleware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CJS default export. No ESM or named exports provided.","symbol":"healthcheck","correct":"const healthcheck = require('healthcheck-middleware')"},{"note":"healthcheck is a factory function, not a middleware directly.","wrong":"app.use('/healthcheck', healthcheck)","symbol":"healthcheck (as middleware)","correct":"app.use('/healthcheck', healthcheck())"},{"note":"Do not call the factory prematurely; pass options at middleware creation.","wrong":"const healthcheck = require('healthcheck-middleware')({ addChecks: ... }); app.use('/healthcheck', healthcheck)","symbol":"healthcheck (with options)","correct":"const healthcheck = require('healthcheck-middleware'); app.use('/healthcheck', healthcheck({ addChecks: ... }))"}],"quickstart":{"code":"const express = require('express');\nconst healthcheck = require('healthcheck-middleware');\n\nconst app = express();\napp.use('/healthcheck', healthcheck({\n  addChecks: (fail, pass) => {\n    // Simulate async check\n    setTimeout(() => {\n      if (Math.random() > 0.5) {\n        pass({ db: 'connected' });\n      } else {\n        fail(new Error('Database unreachable'));\n      }\n    }, 100);\n  },\n  healthInfo: (info) => ({\n    status: info.status,\n    uptime: info.uptime,\n    custom: 'value'\n  })\n}));\napp.listen(3000);","lang":"javascript","description":"Example showing custom checks and health info formatting with Express middleware."},"warnings":[{"fix":"No fix needed; expected behavior.","message":"Empty options object passed but no checks defined; middleware still returns default health info.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use const hc = require('healthcheck-middleware'); then app.use('/healthcheck', hc(options));","message":"Do NOT call require('healthcheck-middleware') with options at require time — that will return middleware, not export the factory.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always pass an Error to fail() for consistency.","message":"fail() called with no argument results in status 'failure' but no message; may be unexpected if you assume error message always present.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Avoid using those keys in pass data or rename them.","message":"pass() with properties named 'status', 'uptime', or 'memoryUsage' will override default values silently.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Catch errors in healthInfo or ensure no throws.","message":"healthInfo throws an Error? Middleware still returns 200 but with 'warning' in status; may mask configuration issues.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use const healthcheck = require('healthcheck-middleware');","cause":"Using ESM import (import) on CJS-only module, or misspelling require.","error":"TypeError: healthcheck is not a function"},{"fix":"app.use('/healthcheck', healthcheck({...}));","cause":"Passing the factory result (healthcheck()) instead of the factory itself to app.use.","error":"TypeError: app.use() requires middleware function"},{"fix":"Add a function that takes two arguments: function(fail, pass) {...}","cause":"addChecks signature expected (fail, pass) but you used different parameter order or forgot to provide callback.","error":"TypeError: fail is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}