Last active
March 28, 2025 17:18
-
-
Save HarlemSquirrel/c635b7f78a411cf68b49614af7256117 to your computer and use it in GitHub Desktop.
TypeScript gRPC health check client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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