Registry / devops / promisify-grpc-client

promisify-grpc-client

JSON →
library4.0.0-alpha.1jsnpmunverified

Utility to convert gRPC client methods generated by @grpc/grpc-js from callback-based to Promise-based, with full TypeScript type declaration support. Current version is 4.0.0-alpha.1, which is an alpha release. The library wraps each client method to return a Promise, preserving the original method signatures and types. It differentiates from generic promisification libraries by being specifically tailored to @grpc/grpc-js generated clients, ensuring correct handling of gRPC errors and metadata. Suitable for projects migrating from callbacks to async/await.

npm install promisify-grpc-client
INSTALL
IMPORT
SIG · PROMISIFY-GRPC-CLI
P
promisify-grpc-client
devopsjavascriptv4.0.0-alpha.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.

promisifyGrpcClient
✓ import promisifyGrpcClient from 'promisify-grpc-client';
✗ const promisifyGrpcClient = require('promisify-grpc-client');
The package is ESM-only since v4.0.0-alpha.1. Use default import.
promisifyGrpcClient
✓ import { promisifyGrpcClient } from 'promisify-grpc-client';
✗ import promisifyGrpcClient from 'promisify-grpc-client';
While the package exports a default, named import is also available. However, the default import is the intended usage.
type PromisifiedClient
✓ import type { PromisifiedClient } from 'promisify-grpc-client';
✗ import { PromisifiedClient } from 'promisify-grpc-client';
In TypeScript, use type-only import to avoid runtime value ambiguity. PromisifiedClient is a type.

Demonstrates importing the default function, creating a gRPC client, promisifying it, and using async/await to call a method.

import promisifyGrpcClient from 'promisify-grpc-client'; import { MyServiceClient } from './generated/my-service_grpc_pb'; const client = new MyServiceClient('localhost:50051', grpc.credentials.createInsecure()); const promisifiedClient = promisifyGrpcClient(client); async function run() { try { const response = await promisifiedClient.myMethod({ name: 'world' }); console.log('Response:', response.getMessage()); } catch (error) { console.error('gRPC error:', error); } } run();
Debug
Known issues
breakingPackage is ESM-only from v4.0.0-alpha.1. CommonJS require() will fail.
fix
Use ES module import or downgrade to v3.x if CommonJS required.
affects: >=4.0.0-alpha.1
deprecatedVersion 4.0.0-alpha.1 is an alpha release and may have breaking changes before stable.
fix
Use at your own risk; pin to exact version and test thoroughly.
affects: 4.0.0-alpha.1
gotchaThe promisify function only works with clients generated by @grpc/grpc-js, not grpc (the deprecated package).
fix
Ensure you are using @grpc/grpc-js and the generated client classes.
affects: >=1.0.0
gotchaTypeScript types may require explicit import of PromisifiedClient for complex scenarios.
fix
Use import type { PromisifiedClient } from 'promisify-grpc-client'; to avoid runtime import.
affects: >=4.0.0-alpha.1
gotchaUnary and response-streaming methods are supported; client-streaming and bidi-streaming methods are not promisified.
fix
Check the documentation for which methods are supported. Use a different pattern for streaming methods.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using require() or running in a CommonJS environment without ESM support.
fix
Set "type": "module" in package.json, or use .mjs extension, or downgrade to v3.x.
TypeError: client.myMethod is not a function
The client does not have the expected method (maybe not generated by @grpc/grpc-js or incorrect client class).
fix
Ensure the client is generated by @grpc/grpc-js and that you are using the correct service client.
Error: Cannot find module 'google-protobuf'
Missing peer dependency google-protobuf.
fix
Install google-protobuf: npm install google-protobuf
Upgrade
Version history
4.0.0-alpha.1latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredpeer dependency: the gRPC client to be promisified must be generated by this package
google-protobufrequiredpeer dependency: required for protobuf types used in gRPC calls
@types/google-protobufoptionalpeer dependency: TypeScript type definitions for google-protobuf
Agent activity
4 hits · last 30 days
node
4
Resources
promisify-grpc-client — npm install promisify-grpc-client · libregistry