Skip to content

Instantly share code, notes, and snippets.

@HarlemSquirrel
Last active March 28, 2025 17:18
Show Gist options
  • Save HarlemSquirrel/c635b7f78a411cf68b49614af7256117 to your computer and use it in GitHub Desktop.
Save HarlemSquirrel/c635b7f78a411cf68b49614af7256117 to your computer and use it in GitHub Desktop.
TypeScript gRPC health check client
// https://github.com/grpc/grpc-node/tree/master/packages/grpc-health-check
import { service as healthServiceDefinition } from 'grpc-health-check';
// https://github.com/grpc/grpc-node/tree/master/packages/grpc-js
import { credentials, makeClientConstructor } from '@grpc/grpc-js';
const HealthClientConstructor = makeClientConstructor(healthServiceDefinition, 'grpc.health.v1.HealthService');
const serverAddress = '0.0.0.0:50051';
const healthClient = new HealthClientConstructor(serverAddress, credentials.createInsecure());
const main = () => {
console.log(`Starting health check on ${serverAddress}`);
healthClient.check({service: ''}, (error: Error, value: string) => {
if (error) {
console.error(`Error checking health: ${error.message}`);
process.exit(1);
}
console.log(value);
process.exit(0);
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment