{"id":17612,"library":"express-healthcheck","title":"Simple Express Healthcheck Middleware","description":"express-healthcheck is a lightweight middleware designed to provide basic health check endpoints for Express.js applications. Released as version 0.1.0 over ten years ago (last published in March 2016), the package is currently unmaintained and effectively abandoned by its original author. It offers a minimal interface to expose an uptime metric and allows for custom `healthy` and `test` functions to provide more application-specific health status, returning a 200 status code with a JSON payload. Unlike more modern and actively maintained health check libraries, it lacks features such as detailed dependency checks, async/await support, built-in security mechanisms, or explicit ESM compatibility, making it suitable only for extremely simple monitoring scenarios or as a historical reference.","status":"abandoned","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/lennym/express-healthcheck","tags":["javascript"],"install":[{"cmd":"npm install express-healthcheck","lang":"bash","label":"npm"},{"cmd":"yarn add express-healthcheck","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-healthcheck","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. Direct ESM imports will fail unless Node.js is configured for interoperability or the code is transpiled. Use `require()` for compatibility.","wrong":"import expressHealthcheck from 'express-healthcheck';","symbol":"expressHealthcheck","correct":"const expressHealthcheck = require('express-healthcheck');"},{"note":"The `express-healthcheck` module exports a function that must be immediately invoked `()` to return the actual middleware, which can then be used with `app.use()`.","wrong":"app.use('/health', require('express-healthcheck'));","symbol":"MiddlewareUsage","correct":"app.use('/health', require('express-healthcheck')());"},{"note":"While `@types/express-healthcheck` exists, the original package does not ship with its own types. The type definitions typically use `export =` syntax, requiring `import = require()` or `esModuleInterop: true` for default import syntax.","wrong":"import { RequestHandler } from 'express-healthcheck';","symbol":"TypeScriptTypes","correct":"import expressHealthcheck = require('express-healthcheck');\n// or if esModuleInterop is true:\nimport expressHealthcheck from 'express-healthcheck';"}],"quickstart":{"code":"const express = require('express');\nconst expressHealthcheck = require('express-healthcheck');\nconst app = express();\n\n// Basic health check endpoint\napp.use('/health', expressHealthcheck());\n\n// Custom health check with a test function\napp.use('/custom-health', expressHealthcheck({\n  test: function () {\n    // Simulate a dependency check, e.g., database connection\n    const isDatabaseHealthy = Math.random() > 0.1;\n    if (!isDatabaseHealthy) {\n      throw new Error('Database connection failed');\n    }\n    return { status: 'Database OK' };\n  },\n  healthy: function () {\n    return { service: 'healthy', timestamp: new Date().toISOString() };\n  }\n}));\n\nconst PORT = process.env.PORT || 3000;\napp.listen(PORT, () => {\n  console.log(`Server running on http://localhost:${PORT}`);\n  console.log(`Basic health check at http://localhost:${PORT}/health`);\n  console.log(`Custom health check at http://localhost:${PORT}/custom-health`);\n});","lang":"javascript","description":"Demonstrates setting up a basic health check and a customized health check endpoint with `express-healthcheck` in an Express application. It includes a simulated asynchronous test for a dependency and a custom healthy response."},"warnings":[{"fix":"Consider migrating to actively maintained health check middleware packages like `express-healthchecker`, `express-actuator-healthcheck`, or implementing custom health check logic for better control and security.","message":"The `express-healthcheck` package is effectively abandoned, with its last release (v0.1.0) dating back to March 2016. It does not receive security updates, bug fixes, or feature enhancements. Using unmaintained software can expose your application to security vulnerabilities and compatibility issues with newer Node.js or Express versions.","severity":"breaking","affected_versions":"0.1.0"},{"fix":"Always use `const expressHealthcheck = require('express-healthcheck');` for this package. If using TypeScript, `import expressHealthcheck = require('express-healthcheck');` is the most robust option, or ensure `esModuleInterop` is enabled in your `tsconfig.json` to allow `import expressHealthcheck from 'express-healthcheck';`.","message":"This package is CommonJS-only. Attempting to import it using ES module `import` syntax (e.g., `import expressHealthcheck from 'express-healthcheck';`) in an ES module context will result in runtime errors like `ERR_REQUIRE_ESM` unless Node.js is specifically configured for CJS-ESM interoperability or a transpilation step is used.","severity":"gotcha","affected_versions":"0.1.0"},{"fix":"If your health check logic involves asynchronous operations (e.g., database queries, external API calls), you must wrap them to fit the expected synchronous return or callback pattern. For complex async checks, a more modern health check library or custom middleware would be more appropriate.","message":"The `test` function provided to `express-healthcheck` for custom logic does not inherently support Promises or async/await. It expects either a synchronous return, a thrown error, or a callback invocation to signal health status. Modern asynchronous operations might not integrate seamlessly without wrapping.","severity":"gotcha","affected_versions":"0.1.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure you call the imported module: `app.use('/health', require('express-healthcheck')());` or `app.use('/health', expressHealthcheck());` if you've assigned the result of `require()` to `expressHealthcheck`.","cause":"The `express-healthcheck` module exports a function that needs to be invoked to return the actual middleware. It's often mistakenly used directly without calling it.","error":"TypeError: expressHealthcheck is not a function"},{"fix":"Revert to CommonJS `require()` syntax: `const expressHealthcheck = require('express-healthcheck');`. If you must use ESM for your project, consider using a more modern health check library that offers explicit ESM support.","cause":"Attempting to `import` a CommonJS-only module (`express-healthcheck`) in an ES module context without proper Node.js configuration or transpilation.","error":"ERR_REQUIRE_ESM"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}