Registry / messaging / grpc-client-egg

grpc-client-egg

JSON →
library0.1.3jsnpmunverified

An Egg.js plugin providing a gRPC client bridge for Node.js microservices. Version 0.1.3 is the current stable release; no known release cadence. It simplifies gRPC service invocation within Egg.js applications by auto-loading proto files, managing connections, and exposing promisified RPC calls via `this.app.grpcClient`. Differentiators: tight integration with Egg.js plugin system, TypeScript type support, and opinionated default loader config (e.g., keepCase, longs-as-String). Suitable for teams building Egg.js backend services with gRPC.

npm install grpc-client-egg
INSTALL
IMPORT
SIG · GRPC-CLIENT-EGG
G
grpc-client-egg
messagingjavascriptv0.1.3
harness data pending
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.

grpcClient (plugin config)
✓ import { EggPlugin } from 'egg'; const plugin: EggPlugin = { grpcClient: { enable: true, package: 'grpc-client-egg' } }; export default plugin
✗ const plugin = { grpcClient: { enable: true, package: 'grpc-client-egg' } }; module.exports = plugin
Must use EggPlugin type and ESM export for Egg.js 3+
this.app.grpcClient
✓ const client = this.app.grpcClient[name].service[package][service]
✗ const client = this.app.grpcClient['main'].greeter.Greeter
Access via app.grpcClient – correctly uses bracket notation for dynamic names
grpc client configuration
✓ import { EggAppConfig, PowerPartial } from 'egg'; const config: PowerPartial<EggAppConfig> = { grpcClient: { clients: [{ name: 'main', protoPath: 'app/proto/main', host: '0.0.0.0', port: 50051 }] } }; export default config
✗ module.exports = { grpcClient: { clients: [{ name: 'main', protoPath: 'app/proto/main', host: '0.0.0.0', port: 50051 }] } }
Must use PowerPartial and ESM export for type safety in Egg.js 3+

Shows complete setup: install, plugin enable, config with proto path, and using promisified client in a service.

// 1. Install // npm i -S grpc-client-egg // 2. Plugin config (plugin.ts) import { EggPlugin } from 'egg' const plugin: EggPlugin = { grpcClient: { enable: true, package: 'grpc-client-egg', }, } export default plugin // 3. Application config (config.default.ts) import { EggAppConfig, PowerPartial } from 'egg' export default () => { const config: PowerPartial<EggAppConfig> = { grpcClient: { clients: [ { name: 'main', protoPath: 'app/proto/main', host: process.env.GRPC_HOST ?? '0.0.0.0', port: Number(process.env.GRPC_PORT ?? 50051), }, ], }, } return config } // 4. Service usage import { Service } from 'egg' interface GreeterService { sayHello(params: { name: string }): Promise<{ message: string }> } export default class Greeter extends Service { readonly service: GreeterService = this.app.grpcClient.main.greeter.Greeter public async sayHello(name: string) { return this.service.sayHello({ name }) } }
Debug
Known issues
gotchaProto file path resolution: protoPath should be relative to app root or absolute; relative paths may break in production.
fix
Use absolute path or path.resolve(__dirname, 'proto') in config.
affects: >=0.1.0
gotchagRPC package compatibility: grpc-client-egg depends on the 'grpc' npm package (not @grpc/grpc-js). Ensure you install grpc version 1.x.
fix
npm install grpc@1.24.11 (last stable version of grpc).
affects: >=0.1.0
deprecatedThe 'grpc' package is deprecated in favor of '@grpc/grpc-js' which is pure JS and actively maintained.
fix
Consider migrating to a plugin that uses @grpc/grpc-js.
affects: >=0.1.0
gotchaLoad balancer: grpc-client-egg does not support load balancing out of the box; clients are single-host connections.
fix
Use a proxy or manual load balancing logic.
affects: >=0.1.0
gotchaProto file changes require restart: proto descriptors are loaded at startup; dynamic proto reload not supported.
fix
Restart the Egg.js application after proto changes.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read property 'Greeter' of undefined
grpcClient service not initialized or invalid client name/service path
fix
Verify client name 'main' matches config, and that proto defines 'greeter.Greeter' service.
Error: Cannot find module 'grpc'
Peer dependency 'grpc' not installed
fix
Run: npm install grpc
Error: ENOENT: no such file or directory, open '/path/to/app/proto/main.proto'
protoPath config is incorrect or file missing
fix
Ensure protoPath is relative to app root or absolute, and the proto file exists.
Error: 14 UNAVAILABLE: failed to connect to all addresses
gRPC server host/port incorrect or server down
fix
Check host and port in config; ensure gRPC server is running and accessible.
TypeError: this.app.grpcClient is undefined
Plugin not enabled or package name wrong
fix
Confirm plugin.ts has correct package name 'grpc-client-egg' and enable: true.
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies
eggrequiredRequires Egg.js application framework to load as plugin
grpcrequiredCore gRPC library for JavaScript
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
grpc-client-egg — npm install grpc-client-egg · libregistry