Registry / devops / grpc-resilient

grpc-resilient

JSON →
library1.1.1jsnpmunverified

Production-ready gRPC client for Node.js microservices and API gateways with built-in resilience patterns. Version 1.1.1 requires Node >=18.0.0 and peer dependencies @grpc/grpc-js >=1.9.0 and @grpc/proto-loader >=0.7.0. Differentiators: lazy connections, auto-reconnect with exponential backoff, configurable retry, fallback cache for graceful degradation, OpenTelemetry-compatible metrics, health checks, TLS/mTLS support, and full TypeScript types with generics. Native ESM support. Released under MIT license.

npm install grpc-resilient
INSTALL
IMPORT
SIG · GRPC-RESILIENT
G
grpc-resilient
devopsjavascriptv1.1.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.

ResilientGrpcClient
import { ResilientGrpcClient } from 'grpc-resilient'
const { ResilientGrpcClient } = require('grpc-resilient')
Package is ESM-only; CommonJS require will fail with ERR_REQUIRE_ESM.
GatewayGrpcClient
import { GatewayGrpcClient } from 'grpc-resilient/gateway'
import { GatewayGrpcClient } from 'grpc-resilient'
GatewayGrpcClient is exported from a subpath export 'grpc-resilient/gateway', not the main package.
type GrpcLogger
import type { GrpcLogger } from 'grpc-resilient'
Use 'import type' for type-only imports to avoid runtime bundling issues.

Shows how to extend ResilientGrpcClient to create a typed microservice client with singleton pattern and generic call method.

import { ResilientGrpcClient, type GrpcLogger } from 'grpc-resilient'; import { fileURLToPath } from 'url'; const logger: GrpcLogger = console; class UserServiceClient extends ResilientGrpcClient { private static instance: UserServiceClient | null = null; private constructor(grpcUrl: string, logger: GrpcLogger) { super({ serviceName: 'UserService', grpcUrl, protoFile: 'user.proto', packageName: 'myapp.user', serviceClassName: 'UserService', protosPath: fileURLToPath(new URL('./protos', import.meta.url)), logger, timeoutMs: 5000, retryCount: 3, enableFallbackCache: true, }); } static getInstance(grpcUrl: string, logger: GrpcLogger): UserServiceClient { if (!UserServiceClient.instance) { UserServiceClient.instance = new UserServiceClient(grpcUrl, logger); } return UserServiceClient.instance; } async getUser(userId: string) { return this.call<{ userId: string }, { id: string; name: string }>('GetUser', { userId }); } } const client = UserServiceClient.getInstance(process.env.GRPC_URL ?? 'localhost:50051', logger); const user = await client.getUser('123'); console.log(user);
Debug
Known issues
breakingPackage is ESM-only and cannot be required() from CommonJS.
fix
Use import syntax or dynamic import() instead of require().
affects: >=1.0.0
gotchaprotosPath must be an absolute path; relative paths will fail silently.
fix
Use fileURLToPath(new URL('./protos', import.meta.url)) or path.resolve().
affects: >=1.0.0
gotchaGatewayGrpcClient is not exported from main barrel; incorrect import will lead to undefined.
fix
Import from 'grpc-resilient/gateway' subpath.
affects: >=1.0.0
deprecatedNo deprecations currently known.
affects: none
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported
Using require() on an ESM-only package from CommonJS.
fix
Change to import { ResilientGrpcClient } from 'grpc-resilient'; or use dynamic import().
Error: ENOENT: no such file or directory, open 'user.proto'
protosPath is relative or the proto file is missing at the specified path.
fix
Provide an absolute path to the protos directory and ensure the proto file exists.
TypeError: (0 , grpc_resilient.GatewayGrpcClient) is not a constructor
Imported GatewayGrpcClient from wrong path; it's undefined.
fix
Import GatewayGrpcClient from 'grpc-resilient/gateway'.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredRequired peer dependency for core gRPC functionality
@grpc/proto-loaderrequiredRequired peer dependency for loading .proto files
Agent activity
6 hits · last 30 days
node
6
Resources
grpc-resilient — npm install grpc-resilient · libregistry