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.
exports.grpcServer
✓ // {app_root}/config/plugin.js
exports.grpcServer = { enable: true, package: 'egg-plugin-grpc-server' }
✗ // Incorrect: do not use require directly in plugin config
exports.grpcServer = require('egg-plugin-grpc-server')
Plugin is declared in plugin.js configuration, not imported directly in code.
new app.GrpcServer(app)
✓ const grpcServer = new app.GrpcServer(app); grpcServer.start();
✗ // Wrong: not imported; it's attached to app by plugin
const GrpcServer = require('egg-plugin-grpc-server'); new GrpcServer(app);
GrpcServer is accessible via app.GrpcServer after plugin is enabled.
exports.grpcServer = { port, host, timeOut, protoDir, grpcDir, errorHandle }
✓ // {app_root}/config/config.default.js
exports.grpcServer = { port: 50051 }
✗ // Wrong: must be inside exports object, not just setting grpcServer directly
grpcServer = { port: 50051 }
Configuration is part of Egg's config merge mechanism.
Shows plugin configuration and basic startup in an Egg.js application, including plugin enablement, config, and gRPC server lifecycle.
// {app_root}/config/plugin.js
exports.grpcServer = {
enable: true,
package: 'egg-plugin-grpc-server',
};
// {app_root}/config/config.default.js
exports.grpcServer = {
port: 50051,
host: '127.0.0.1',
timeOut: 5000,
protoDir: 'app/proto',
grpcDir: 'app/grpc',
errorHandle(error) {
// this is ctx
console.error(error);
},
};
// {app_root}/app.js (startup code)
module.exports = app => {
app.beforeStart(async () => {
const grpcServer = new app.GrpcServer(app);
await grpcServer.start();
app.grpcServer = grpcServer;
});
app.beforeClose(async () => {
await app.grpcServer.close();
});
};
Errors
Common errors & fixes
Error: listen EADDRINUSE :::50051
Multiple worker processes trying to start the same gRPC server on same port.
fixUse cluster-client approach to ensure only one worker starts the server, or start in agent process.
TypeError: app.GrpcServer is not a constructor
Plugin not enabled correctly in config/plugin.js.
fixEnsure plugin is enabled with correct package name 'egg-plugin-grpc-server'.
Audit
Dependencies
eggrequiredEgg.js framework required as peer dependency