Registry / devops / grpc-utils

grpc-utils

JSON →
library1.0.27jsnpmunverified

A TypeScript utility library (v1.0.27) that reduces boilerplate for gRPC operations in Node.js. It provides a GrpcClient class that auto-generates promise-based methods from proto definitions, plus helpers like encodeMetadata/decodeMetadata and grpcLoader for loading proto files. Ships with TypeScript types. Suitable for projects using gRPC with Node.js, aiming to simplify client setup and metadata handling. Alternates like @grpc/proto-loader and grpc itself require more manual wiring; grpc-utils abstracts common patterns.

npm install grpc-utils
INSTALL
IMPORT
SIG · GRPC-UTILS
G
grpc-utils
devopsjavascriptv1.0.27
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
import { GrpcClient } from 'grpc-utils';
const GrpcClient = require('grpc-utils');
ESM-only; CommonJS is not supported. Requires TypeScript or ES modules.
encodeMetadata
import { encodeMetadata } from 'grpc-utils';
Named export for encoding metadata.
grpcLoader
import { grpcLoader } from 'grpc-utils';
Utility object with loadProto methods.

Initializes a GrpcClient from a proto definition and calls a generated method with async/await.

import { GrpcClient } from 'grpc-utils'; import * as protoLoader from '@grpc/proto-loader'; import * as grpc from '@grpc/grpc-js'; const packageDefinition = protoLoader.loadSync('path/to/service.proto'); const proto = grpc.loadPackageDefinition(packageDefinition); const client = new GrpcClient( proto.my_package.MyService, 'localhost:50051', grpc.credentials.createInsecure() ); async function main() { try { const response = await client.myMethod({ requestField: 'value' }); console.log('Response:', response); } catch (error) { console.error('Error:', error); } } main();
Debug
Known issues
breakingMethod names are auto-generated from proto RPC names; they may be renamed across versions.
fix
Check generated method names after upgrade and adjust invocations.
affects: 0.x to 1.x
deprecatedOlder usage relied on `grpc` package (grpc); now requires `@grpc/grpc-js`.
fix
Replace `const grpc = require('grpc')` with `import * as grpc from '@grpc/grpc-js'`.
affects: <1.0
gotchaGrpcClient expects a constructed gRPC client constructor, not a class. Passing the wrong object type will throw at runtime.
fix
Ensure the first argument is a gRPC client constructor (e.g., from `proto.my_package.MyService`) not an instance.
affects: *
Errors
Common errors & fixes
ReferenceError: grpc is not defined
Missing import for @grpc/grpc-js
fix
Install and import @grpc/grpc-js: `npm install @grpc/grpc-js` and add `import * as grpc from '@grpc/grpc-js'`.
TypeError: client.myMethod is not a function
RPC method name mismatch or proto not loaded correctly
fix
Check proto file path and ensure the method exists; generated method names are camelCase of proto RPC names.
Upgrade
Version history
1.0.27latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredCore gRPC implementation for Node.js
@grpc/proto-loaderrequiredLoads .proto files and generates type definitions
protobufjsoptionalUsed internally by GRPC-utils for metadata encoding/decoding
Agent activity
8 hits · last 30 days
node
8
Resources
grpc-utils — npm install grpc-utils · libregistry