Registry / devops / grpc-js-helper

grpc-js-helper

JSON →
library0.3.0jsnpmunverified

A utility library for @grpc/grpc-js providing helper types and functions such as ServiceError, ServiceStatus, and serviceCall for easier gRPC error handling and status codes. Version 0.3.0 is current, with stable release cadence. Key differentiators: lightweight, type-safe wrappers for gRPC client calls, and consistent error handling patterns.

npm install grpc-js-helper
INSTALL
IMPORT
SIG · GRPC-JS-HELPER
G
grpc-js-helper
devopsjavascriptv0.3.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.

ServiceError
import { ServiceError } from 'grpc-js-helper'
import ServiceError from 'grpc-js-helper'
Named export, not default.
ServiceStatus
import { ServiceStatus } from 'grpc-js-helper'
const { ServiceStatus } = require('grpc-js-helper')
ESM only; Node >=20 required.
serviceCall
import { serviceCall } from 'grpc-js-helper'
Async function that wraps gRPC client methods.

Shows how to use serviceCall with a gRPC client, handle ServiceError, and check ServiceStatus codes.

import { ServiceError, ServiceStatus, serviceCall } from 'grpc-js-helper'; import * as grpc from '@grpc/grpc-js'; import protoLoader from '@grpc/proto-loader'; const packageDefinition = protoLoader.loadSync('helloworld.proto'); const proto = grpc.loadPackageDefinition(packageDefinition).helloworld; const client = new proto.Greeter('localhost:50051', grpc.credentials.createInsecure()); async function sayHello(name: string) { try { const response = await serviceCall(client.sayHello({ name })); console.log('Greeting:', response.message); } catch (error) { if (error instanceof ServiceError) { console.error('gRPC error:', error.code, error.details); } else { console.error('Unexpected error:', error); } } } sayHello(process.env.NAME ?? 'World');
Debug
Known issues
gotcha`serviceCall` expects a gRPC ClientUnaryCall object, not a Promise.
fix
Pass the return value of a gRPC client method (e.g., client.sayHello({...})), not await it.
affects: >=0.0.0
breakingRequires Node >=20 due to ESM-only exports.
fix
Update Node.js to >=20 or use an older version of the package.
affects: >=0.3.0
deprecatedThe package may not be actively maintained; check before use in production.
fix
Monitor GitHub for updates or consider alternatives.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: serviceCall is not a function
Default import used instead of named import.
fix
Use `import { serviceCall } from 'grpc-js-helper'` instead of `import serviceCall from 'grpc-js-helper'`.
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Package is ESM-only, cannot use require().
fix
Use import syntax or switch to dynamic import(). Ensure Node >=20.
Class extends value undefined is not a constructor or null
`@grpc/grpc-js` not installed.
fix
Run `npm install @grpc/grpc-js`.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredpeer dependency for gRPC client functionality
Agent activity
5 hits · last 30 days
node
5
Resources
grpc-js-helper — npm install grpc-js-helper · libregistry