Registry / devops / multi-proto-grpc-server

multi-proto-grpc-server

JSON →
library3.0.0jsnpmunverified

Wrapper around the official grpc npm package that simplifies handling multiple proto files for various gRPC clients communicating with a single server. Version 3.0.0 supports Node 8.0+ and provides a ServiceMap class to bind service implementations and a GRPC class to start the server on a given address. It differentiates from raw gRPC by offering a declarative configuration for multiple services and proto files. Release cadence is not specified; the package appears to be in early development with upcoming features like authentication.

npm install multi-proto-grpc-server
INSTALL
IMPORT
SIG · MULTI-PROTO-GRPC-S
M
multi-proto-grpc-server
devopsjavascriptv3.0.0
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.

GRPC
import { GRPC } from 'multi-proto-grpc-server'
const GRPC = require('multi-proto-grpc-server').GRPC
CommonJS destructuring works with require; ESM import syntax is recommended for modern code.
ServiceMap
import { ServiceMap } from 'multi-proto-grpc-server'
const { ServiceMap } = require('multi-proto-grpc-server')
Named export; common mistake is to import as default.
GRPC class instance
const server = new GRPC(configs); server.run('0.0.0.0:50051');
GRPC(configs).run('0.0.0.0:50051')
GRPC must be instantiated with new before calling run().

Demonstrates creating a gRPC server with a single proto service using ServiceMap and GRPC classes.

const { GRPC, ServiceMap } = require('multi-proto-grpc-server'); // Define service implementations as objects with methods matching RPC names const notificationService = { send: (call, callback) => { callback(null, { response: 'Notification sent' }); } }; // Create a ServiceMap for each proto package const notificationServiceMap = new ServiceMap('notification', notificationService); // Configuration array for each proto file const server = new GRPC([ { packageName: 'notification', serviceName: 'Notification', PROTO_PATH: './notification.proto', serviceMap: notificationServiceMap.map } ]); // Start the server server.run('0.0.0.0:50051');
Debug
Known issues
gotchaThe package uses the deprecated 'grpc' module, which has been superseded by '@grpc/grpc-js'. The 'grpc' module is no longer maintained and may have compatibility issues with newer Node versions.
fix
Migrate to '@grpc/grpc-js' and use its server implementation directly, or ensure that the 'grpc' module works in your environment.
affects: >=1.0.0
breakingThe PROTO_PATH must be an absolute or relative path to the .proto file. Relative paths are resolved from the current working directory, which may differ from the script location.
fix
Use path.resolve(__dirname, './notification.proto') to ensure correct path resolution.
affects: >=1.0.0
gotchaThe ServiceMap constructor requires the package name exactly as declared in the proto file's 'package' statement, including case sensitivity. Mismatches cause silent failures.
fix
Verify the 'package' line in the proto file and use the exact same string.
affects: >=1.0.0
deprecatedThe serviceMap property passed to GRPC config must be obtained from ServiceMap.map. Directly passing a plain object may lead to undefined behavior.
fix
Always use ServiceMap instance's map property (e.g., serviceMap: myServiceMap.map).
affects: >=2.0.0
gotchaThe proto file syntax must be proto3; proto2 is not supported and will cause errors.
fix
Ensure all .proto files start with 'syntax = "proto3";'.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'grpc'
The 'grpc' package is not installed as a direct dependency; it is a peer dependency that must be installed separately.
fix
Run 'npm install grpc' in your project.
TypeError: ServiceMap is not a constructor
ServiceMap is imported incorrectly, e.g., as a default import instead of named import.
fix
Use: const { ServiceMap } = require('multi-proto-grpc-server');
Error: ENOENT: no such file or directory, open './notification.proto'
The PROTO_PATH is a relative path that does not exist relative to the current working directory.
fix
Use path.resolve(__dirname, './notification.proto') to provide an absolute path.
TypeError: server.run is not a function
GRPC was not instantiated with 'new', so run() is undefined.
fix
Use: const server = new GRPC(configs); server.run(address);
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
grpcrequiredcore gRPC library for Node.js
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources