Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
HealthImplementation
✓ import { HealthImplementation } from 'grpc-health-check'
✗ const { HealthImplementation } = require('grpc-health-check')
ESM import only; package does not support CommonJS require
ServingStatusMap
✓ import { ServingStatusMap } from 'grpc-health-check'
✗ import ServingStatusMap from 'grpc-health-check'
Named import, not default. TypeScript type.
service
✓ import { service } from 'grpc-health-check'
✗ const service = require('grpc-health-check').service
ESM only; used to generate client stubs
servingStatus
✓ import { servingStatus } from 'grpc-health-check'
✗ import servingStatus from 'grpc-health-check'
Named import, not default.
protoPath
✓ import { protoPath } from 'grpc-health-check'
Exported path to health.proto for CLI usage
Creates a gRPC server with health check service, adds health implementation with status map, and starts listening on port 50051.
import { HealthImplementation, ServingStatusMap } from 'grpc-health-check';
import * as grpc from '@grpc/grpc-js';
const server = new grpc.Server();
const statusMap: ServingStatusMap = {
'': 'NOT_SERVING',
'MyService': 'SERVING',
};
const healthImpl = new HealthImplementation(statusMap);
healthImpl.addToServer(server);
server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => {
server.start();
console.log('Server with health check running on 0.0.0.0:50051');
});
Errors
Common errors & fixes
Cannot find module 'grpc-health-check' or its corresponding type declarations.
Missing peer dependencies or incorrect import syntax.
fixInstall peer dependencies: npm install @grpc/grpc-js @grpc/proto-loader. Use ESM import.
TypeError: grpc.health.check is not a function
Incorrect usage: trying to call health check as a function instead of using the service.
fixImport { service } and use it to create a client via grpc.makeGenericClientConstructor. Error: 12 UNIMPLEMENTED: unknown service grpc.health.v1.Health
Server does not have the health implementation added.
fixCall healthImpl.addToServer(server) after constructing the HealthImplementation.
Type '{}' is not assignable to parameter of type 'ServingStatusMap'
Empty object provided instead of a proper status map.
fixPass an object with at least the '' key, e.g., { '': 'SERVING' }. Audit
Dependencies
@grpc/grpc-jsrequiredPeer dependency for gRPC functionality
@grpc/proto-loaderrequiredUsed for loading .proto files