Registry / observability / server-health

server-health

JSON →
library7.0.0jsnpmunverified

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.

npm install server-health
INSTALL
IMPORT
SIG · SERVER-HEALTH
S
server-health
observabilityjavascriptv7.0.0
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.

serverHealth
import serverHealth from 'server-health'; // For ESM environments
const serverHealth = require('server-health'); // Legacy CJS, but shown in docs
The library's README primarily uses CommonJS `require()`. While `server-health` v7.0.0 requires Node.js v20+, which fully supports ESM, ensure your project's module system is correctly configured. A default import is expected for ESM.
addConnectionCheck
import serverHealth from 'server-health'; serverHealth.addConnectionCheck('db', () => true);
import { addConnectionCheck } from 'server-health'; // Not a named export
This function is a method of the main `serverHealth` object. It is not a named export.
exposeHealthEndpoint
import serverHealth from 'server-health'; serverHealth.exposeHealthEndpoint(server, '/health', 'fastify');
import { exposeHealthEndpoint } from 'server-health'; // Not a named export
This function is a method of the main `serverHealth` object. It is not a named export.
createNodeHttpHealthCheckServer
import serverHealth from 'server-health'; const nodeServer = serverHealth.createNodeHttpHealthCheckServer({});
import { createNodeHttpHealthCheckServer } from 'server-health'; // Not a named export
This function is a method of the main `serverHealth` object for creating a standalone health server. It is not a named export.

Demonstrates initializing `server-health` with a Fastify server, adding custom connection checks, and exposing the `/health` endpoint.

import serverHealth from 'server-health'; import fastify from 'fastify'; // Add custom connection checks serverHealth.addConnectionCheck('database', function () { // In a real application, this would check actual database connectivity. // For this example, we'll simulate a healthy connection. return true; }); serverHealth.addConnectionCheck('redis', function () { // Simulate a healthy Redis connection return true; }); const server = fastify(); // Expose the health endpoint on the Fastify server serverHealth.exposeHealthEndpoint(server, '/health', 'fastify'); const PORT = process.env.PORT ?? 8080; server.listen({ port: PORT }, (err) => { if (err) { server.log.error(err); process.exit(1); } console.log(`Server listening on http://localhost:${PORT}`); console.log(`Health endpoint available at http://localhost:${PORT}/health`); });
Debug
Known issues
breakingVersion 7.0.0 of `server-health` drops support for Node.js v18. Applications must upgrade to Node.js v20.0.0 or higher to use this version.
fix
Upgrade your Node.js runtime to version 20.0.0 or newer. Consider using Node.js LTS versions for stability.
affects: >=7.0.0
breakingVersion 7.0.0 of `server-health` drops support for Restify when running on Node.js v24. If using Restify on Node.js v24, you may need to downgrade `server-health` or migrate away from Restify.
fix
If using Restify on Node.js v24, consider staying on `server-health` v6.x or migrating your application to use a different framework like Fastify or Express, or a newer version of Restify if available and compatible.
affects: >=7.0.0
breakingVersion 6.0.0 of `server-health` requires Node.js v18 or higher. Projects running on older Node.js versions (e.g., v16 or v12) will encounter compatibility issues.
fix
Upgrade your Node.js runtime to version 18.0.0 or newer (for v6.x) or to v20.0.0 or newer (for v7.x).
affects: >=6.0.0 <7.0.0
gotchaThe `server-health` documentation and examples predominantly use CommonJS `require()` syntax. While v7.0.0 targets Node.js v20+, which supports ESM, developers in pure ESM projects should use `import` statements and handle the default export.
fix
For ESM projects, use `import serverHealth from 'server-health';`. Ensure your `package.json` specifies `"type": "module"` or uses `.mjs` extensions where appropriate.
affects: >=6.0.0
Errors
Common errors & fixes
Error: Cannot find module 'server-health'
The `server-health` package is not installed in your project's `node_modules`.
fix
Run `npm install server-health` or `yarn add server-health` to install the package.
TypeError: serverHealth.exposeHealthEndpoint is not a function
The `serverHealth` object was not correctly imported or is undefined, likely due to incorrect CommonJS/ESM usage or a typo.
fix
Ensure you are using `const serverHealth = require('server-health');` for CommonJS or `import serverHealth from 'server-health';` for ESM, and that the package is correctly installed.
The 'framework' argument must be one of 'restify', 'express', 'hapi', 'fastify', or 'http'
The third argument to `exposeHealthEndpoint` (the framework string) is invalid or misspelled.
fix
Provide a valid string for the framework: `'restify'`, `'express'`, `'hapi'`, `'fastify'`, or `'http'` (for vanilla Node.js `http` server).
Upgrade
Version history
7.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
2
Resources
server-health — npm install server-health · libregistry