Registry / observability / healthcheck-middleware

healthcheck-middleware

JSON →
library1.0.1jsnpmunverified

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.

npm install healthcheck-middleware
INSTALL
IMPORT
SIG · HEALTHCHECK-MIDDLE
H
healthcheck-middleware
observabilityjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

healthcheck
const healthcheck = require('healthcheck-middleware')
CJS default export. No ESM or named exports provided.
healthcheck (as middleware)
app.use('/healthcheck', healthcheck())
app.use('/healthcheck', healthcheck)
healthcheck is a factory function, not a middleware directly.
healthcheck (with options)
const healthcheck = require('healthcheck-middleware'); app.use('/healthcheck', healthcheck({ addChecks: ... }))
const healthcheck = require('healthcheck-middleware')({ addChecks: ... }); app.use('/healthcheck', healthcheck)
Do not call the factory prematurely; pass options at middleware creation.

Example showing custom checks and health info formatting with Express middleware.

const express = require('express'); const healthcheck = require('healthcheck-middleware'); const app = express(); app.use('/healthcheck', healthcheck({ addChecks: (fail, pass) => { // Simulate async check setTimeout(() => { if (Math.random() > 0.5) { pass({ db: 'connected' }); } else { fail(new Error('Database unreachable')); } }, 100); }, healthInfo: (info) => ({ status: info.status, uptime: info.uptime, custom: 'value' }) })); app.listen(3000);
Debug
Known issues
gotchaEmpty options object passed but no checks defined; middleware still returns default health info.
fix
No fix needed; expected behavior.
affects: >=0.1.0
gotchaDo NOT call require('healthcheck-middleware') with options at require time — that will return middleware, not export the factory.
fix
Use const hc = require('healthcheck-middleware'); then app.use('/healthcheck', hc(options));
affects: >=0.1.0
gotchafail() called with no argument results in status 'failure' but no message; may be unexpected if you assume error message always present.
fix
Always pass an Error to fail() for consistency.
affects: >=0.1.0
gotchapass() with properties named 'status', 'uptime', or 'memoryUsage' will override default values silently.
fix
Avoid using those keys in pass data or rename them.
affects: >=0.1.0
gotchahealthInfo throws an Error? Middleware still returns 200 but with 'warning' in status; may mask configuration issues.
fix
Catch errors in healthInfo or ensure no throws.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: healthcheck is not a function
Using ESM import (import) on CJS-only module, or misspelling require.
fix
Use const healthcheck = require('healthcheck-middleware');
TypeError: app.use() requires middleware function
Passing the factory result (healthcheck()) instead of the factory itself to app.use.
fix
app.use('/healthcheck', healthcheck({...}));
TypeError: fail is not a function
addChecks signature expected (fail, pass) but you used different parameter order or forgot to provide callback.
fix
Add a function that takes two arguments: function(fail, pass) {...}
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
healthcheck-middleware — npm install healthcheck-middleware · libregistry