{"library":"nice-grpc-server-reflection","title":"nice-grpc Server Reflection","description":"nice-grpc-server-reflection is a package within the nice-grpc ecosystem that provides gRPC server reflection capabilities for Node.js servers built with nice-grpc. Currently at version 3.0.4, it enables external gRPC tools like `grpcurl`, Postman, or client libraries to dynamically discover and introspect the server's exposed services, methods, and their protobuf message definitions at runtime without requiring pre-compiled `.proto` files on the client side. The library integrates seamlessly with the `nice-grpc` server, accepting a pre-generated protobuf descriptor set (.bin file) and a list of fully-qualified service names. As part of the actively maintained `nice-grpc` monorepo, it receives frequent updates, leveraging nice-grpc's TypeScript-first design, modern Promises/Async Iterables API, and robust middleware support. Its primary differentiator is its tight integration and idiomatic usage within the `nice-grpc` framework, providing a clear path for enabling standard gRPC reflection in TypeScript-based Node.js gRPC services.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install nice-grpc-server-reflection"],"cli":null},"imports":["import { ServerReflectionService } from 'nice-grpc-server-reflection'","import { ServerReflection } from 'nice-grpc-server-reflection'","import { Server as GrpcServer } from 'nice-grpc'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Server as GrpcServer, ServiceDefinition, UntypedServiceImplementation } from 'nice-grpc';\nimport { ServerReflectionService, ServerReflection } from 'nice-grpc-server-reflection';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\n// 1. Define your .proto file (e.g., proto/greeting.proto):\n//    syntax = \"proto3\";\n//    package greeting;\n//    service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} }\n//    message HelloRequest { string name = 1; }\n//    message HelloReply { string message = 1; }\n\n// 2. Generate the descriptor set using protoc:\n//    `protoc --descriptor_set_out=./proto/bundle.bin --include_imports -I./proto ./proto/greeting.proto`\n\n// 3. Define your gRPC service implementation\nconst greeterService: ServiceDefinition & UntypedServiceImplementation = {\n  path: '/greeting.Greeter/SayHello',\n  requestStream: false,\n  responseStream: false,\n  requestType: {} as any, // In a real app, these would be generated types\n  responseType: {} as any, // In a real app, these would be generated types\n  async handler(request: { name: string }) {\n    return { message: `Hello, ${request.name}!` };\n  }\n};\n\nconst main = async () => {\n  const server = new GrpcServer();\n\n  // Load the generated protobuf descriptor set\n  const protoset = fs.readFileSync(path.join(__dirname, '../proto/bundle.bin'));\n\n  // Add your application service\n  server.add('greeting.Greeter', greeterService);\n\n  // Add the server reflection service\n  // Pass the protoset and a list of fully-qualified service names to expose\n  server.add(\n    ServerReflectionService,\n    ServerReflection(\n      protoset,\n      ['greeting.Greeter']\n    )\n  );\n\n  const port = 50051;\n  await server.listen(`0.0.0.0:${port}`);\n  console.log(`nice-grpc server with reflection listening on port ${port}`);\n\n  // You can now use grpcurl to inspect and call services:\n  // `grpcurl -plaintext localhost:50051 list`\n  // `grpcurl -plaintext localhost:50051 describe greeting.Greeter`\n  // `grpcurl -plaintext -d '{\"name\": \"World\"}' localhost:50051 greeting.Greeter/SayHello`\n};\n\nmain().catch(console.error);\n","lang":"typescript","description":"This quickstart demonstrates how to set up a nice-grpc server, define a simple gRPC service, generate a protobuf descriptor set, and enable the gRPC Server Reflection service. It includes the necessary `protoc` command to create the `.bin` file and shows how to integrate it with `nice-grpc`, allowing tools like `grpcurl` to inspect the running server's API.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}