Registry / devops / grpc-promise2

grpc-promise2

JSON →
library2.4.1jsnpmunverified

A library to promisify all gRPC request/response types (unary, client stream, server stream, bidirectional stream) for Node.js. Version 2.4.1 is a fork of grpc-promise with extended metadata support. It provides a consistent promise-based API over the callback-driven @grpc/grpc-js and grpc packages. Key differentiator: supports metadata and deadlines while standardizing stream and unary calls. Maintenance is low, with infrequent releases.

npm install grpc-promise2
INSTALL
IMPORT
SIG · GRPC-PROMISE2
G
grpc-promise2
devopsjavascriptv2.4.1
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.

makeGrpcClient
import { makeGrpcClient } from 'grpc-promise'
Default function to enhance a gRPC client instance with promise-based methods.
promisify
import { promisify } from 'grpc-promise'
Used to promisify individual gRPC functions rather than entire clients.
default import
import grpcPromise from 'grpc-promise'
const grpcPromise = require('grpc-promise')
CJS require works but TS/ESM users should use default import for better intellisense.

Shows how to create a gRPC client, promisify it, and make a unary call using async/await.

import * as grpc from '@grpc/grpc-js'; import * as protoLoader from '@grpc/proto-loader'; import { makeGrpcClient } from 'grpc-promise'; const packageDefinition = protoLoader.loadSync('test.proto'); const proto = grpc.loadPackageDefinition(packageDefinition); const client = new proto.test.Test('localhost:50051', grpc.credentials.createInsecure()); const promClient = makeGrpcClient(client); async function callUnary() { try { const response = await promClient.testSimpleSimple({ id: 1 }).sendMessage(); console.log('Response:', response); } catch (err) { console.error(err); } } callUnary();
Debug
Known issues
gotchaThe library expects a gRPC client instance that uses the 'grpc' package or '@grpc/grpc-js'. Using a client from a different gRPC library (e.g., 'grpc-web') will cause errors.
fix
Ensure your gRPC client is created with '@grpc/grpc-js' or 'grpc'.
affects: *
gotchaPromisified stream methods (client stream, server stream, bidi) require calling .sendMessage() differently than unary calls. For streams, you must call .sendMessage() after writing to the stream or setting up listeners.
fix
For client streams: promClient.testStreamSimple().write({ id: 1 }).end().sendMessage(). For server streams: promClient.testSimpleStream({ id: 1 }).sendMessage() returns a promise that fulfills when stream ends.
affects: *
gotchaMetadata is passed as the second argument to the promisified method, not as part of the call options.
fix
Use promClient.testSimpleSimple({ id: 1 }, metadata).sendMessage() instead of options object.
affects: *
deprecatedThe original 'grpc-promise' package (non-fork) is unmaintained and has known issues with newer versions of @grpc/grpc-js.
fix
Use this fork (grpc-promise2) which is updated for @grpc/grpc-js.
affects: *
gotchaThe library does not support TypeScript generics for typed responses; you may need to cast response types manually.
fix
Use type assertions: const response = (await promClient.testMethod(...).sendMessage()) as MyResponseType;
affects: *
Errors
Common errors & fixes
TypeError: client.testSimpleSimple is not a function
The client was not promisified with makeGrpcClient before calling promisified methods.
fix
Call makeGrpcClient(client) to return a new client with promisified methods.
Error: Cannot read properties of undefined (reading 'sendMessage')
Attempting to call .sendMessage() on a promisified method that returns a stream without proper invocation.
fix
Ensure you are using the correct pattern: for unary, call .sendMessage() directly on the returned object; for streams, write/end then call .sendMessage().
Metadata is not a function
Passing metadata as part of an options object instead of a separate argument.
fix
Pass metadata as the second argument: client.method(request, metadata).sendMessage()
UnhandledPromiseRejectionWarning: Error: 12 UNIMPLEMENTED
The gRPC server does not implement the called method or the method name does not match the proto definition.
fix
Verify the method name on the client matches exactly with the rpc name in the .proto file.
Upgrade
Version history
2.4.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources