Registry / devops / egg-grpc-util

egg-grpc-util

JSON →
library3.0.6jsnpmunverified

An Egg.js plugin that simplifies gRPC server and client setup with auto-configuration and manual configuration options. Version 3.0.6 supports basic unary RPCs (no streaming). It provides a convenient way to define gRPC services and clients by scanning proto files and mapping them to Egg.js services. The plugin is tailored for the Egg.js framework and requires Node >=8.0.0. Compared to other gRPC Node.js libraries, this plugin integrates deeply with Egg.js's plugin system, offering auto-configuration that reduces boilerplate, but with limitations on proto file structure and function naming conventions.

npm install egg-grpc-util
INSTALL
IMPORT
SIG · EGG-GRPC-UTIL
E
egg-grpc-util
devopsjavascriptv3.0.6
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.

grpcUtil
// configure in plugin.js and config.default.js (not imported directly)
const grpcUtil = require('egg-grpc-util');
This plugin is not imported directly; it's configured as an Egg.js plugin in plugin.js and config.default.js. The grpcUtil will be attached to the app instance as app.grpcUtil automatically.
app.grpcUtil
// access via app.grpcUtil in controller/service (not imported)
const grpcUtil = require('egg-grpc-util');
After enabling the plugin, it is available as app.grpcUtil. It provides methods like startServer and getClient.

Demonstrates basic setup for Egg.js gRPC plugin: enabling plugin, configuring auto-configuration for server/client with proto path, and defining a proto file and corresponding service.

// {app_root}/config/plugin.js exports.grpcUtil = { enable: true, package: 'egg-grpc-util', }; // {app_root}/config/config.default.js exports.grpcUtil = { rpcServer: { host: '0.0.0.0', port: 50051, autoConfig: 1, protoPath: 'app/proto', }, rpcClient: { host: '0.0.0.0', port: 50051, autoConfig: 1, protoPath: 'app/proto', }, }; // {app_root}/app/proto/example.proto syntax = "proto3"; package example; service example { rpc sayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string name = 1; } message HelloReply { string message = 1; } // {app_root}/app/service/example.js const Service = require('egg').Service; class ExampleService extends Service { async sayHello({ name }) { return { message: `Hello, ${name}!` }; } } module.exports = ExampleService; // Start server and client automatically via app lifecycle
Debug
Known issues
gotchaAuto-configuration requires strict naming conventions: proto file name, package, service, and function names must match exactly, and functions must accept a single object argument.
fix
Follow naming conventions or use manual configuration with protoArray to specify mappings.
affects: >=0.0.0
gotchaPlugin only supports simple unary RPC calls; streaming (server-streaming, client-streaming, bidirectional) is not supported.
fix
Consider using grpc library directly for streaming use cases.
affects: >=0.0.0
gotchaProto files must be placed under the specified protoPath (default: app/proto) for auto-configuration to work.
fix
Ensure proto files are in the correct directory or manually configure protoArray with absolute or relative paths.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'grpc'
The grpc package is not installed as a dependency.
fix
Run `npm install grpc --save` to install the grpc peer dependency.
TypeError: Cannot read property 'startServer' of undefined
The plugin is not enabled or not loaded correctly; app.grpcUtil is missing.
fix
Ensure plugin.js exports { grpcUtil: { enable: true, package: 'egg-grpc-util' } } and that the package is installed.
Error: ENOENT: no such file or directory, open 'app/proto/example.proto'
The proto file path is incorrect or the file does not exist.
fix
Verify that the proto file exists at the configured protoPath (default: app/proto) or use an absolute path in manual configuration.
Error: Cannot find service 'example.example' in proto file
The package name and service name in the proto file do not match the expected format used in auto-configuration.
fix
Ensure the proto file has consistent naming: package name matches service name and file name (e.g., package example; service example { ... })
Upgrade
Version history
3.0.6latest on npm
Audit
Dependencies
grpcrequiredRequired for gRPC server and client functionality.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
egg-grpc-util — npm install egg-grpc-util · libregistry