Registry / devops / nestjs-grpc-client

nestjs-grpc-client

JSON →
library0.1.8jsnpmunverified

A NestJS module for dynamically configuring gRPC clients with injectable service addresses, instead of hardcoding URLs. Version 0.1.8 supports synchronous (register) and asynchronous (registerAsync) configuration, decorators (InjectGrpcClient, InjectGrpcClientService) for injecting ClientGrpcProxy or specific gRPC services. Unlike NestJS built-in @Client() which requires static addresses, this library allows runtime configuration via dependency injection. Heavily reliant on @nestjs/microservices and protobufjs. Limited community adoption and infrequent releases.

npm install nestjs-grpc-client
INSTALL
IMPORT
SIG · NESTJS-GRPC-CLIENT
N
nestjs-grpc-client
devopsjavascriptv0.1.8
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.

GrpcClientModule
import { GrpcClientModule } from 'nestjs-grpc-client'
import GrpcClientModule from 'nestjs-grpc-client'
Default export is not available; use named import.
InjectGrpcClient
import { InjectGrpcClient } from 'nestjs-grpc-client'
const { InjectGrpcClient } = require('nestjs-grpc-client')
CJS require works but ESM preferred in modern NestJS.
InjectGrpcClientService
import { InjectGrpcClientService } from 'nestjs-grpc-client'
Always use named import; no default export.

Shows synchronous registration of a gRPC client module and injection of the client proxy via InjectGrpcClient decorator.

import { Module } from '@nestjs/common'; import { GrpcClientModule } from 'nestjs-grpc-client'; import { Transport } from '@nestjs/microservices'; import { join } from 'path'; @Module({ imports: [ GrpcClientModule.register([ { transport: Transport.GRPC, options: { url: '0.0.0.0:8888', package: 'hello', protoPath: join(__dirname, 'hello.proto'), loader: { arrays: true } } } ]) ] }) export class AppModule {} // In a service: import { Injectable } from '@nestjs/common'; import { InjectGrpcClient } from 'nestjs-grpc-client'; import { ClientGrpcProxy } from '@nestjs/microservices'; @Injectable() export class TestService { constructor( @InjectGrpcClient('hello') private grpcClient: ClientGrpcProxy, ) {} async hello() { const helloService: any = this.grpcClient.getService('HelloService'); return await helloService.say('hello'); } }
Debug
Known issues
gotchaThe package version (0.1.8) is early-stage; APIs may change without notice.
fix
Pin to exact version and test upgrades.
affects: *
gotchaInjectGrpcClientService requires prior registration via GrpcClientModule.forClientServices in the importing module.
fix
Ensure forClientServices is called in the module that provides the service where InjectGrpcClientService is used.
affects: *
deprecatedThe module uses @nestjs/microservices ClientGrpcProxy which is deprecated in NestJS 9+ in favor of @grpc/grpc-js.
fix
Consider using @grpc/grpc-js directly or migrating to NestJS 10+ with new gRPC support.
affects: >=0.1.0
gotchaThe proto file must be loaded with correct paths; relative paths may fail in production builds.
fix
Use absolute paths or dynamic __dirname based resolution.
affects: *
Errors
Common errors & fixes
Cannot find module 'nestjs-grpc-client'
Package not installed or typo in package name
fix
Run 'npm install nestjs-grpc-client' or check package.json dependencies.
InjectGrpcClientService cannot find service 'HelloService' for package 'hello'
Service not registered via forClientServices or misspelled service name
fix
Add the service to forClientServices array and ensure proto defines it correctly.
Property 'getService' does not exist on type 'ClientGrpcProxy'.
TypeScript strict mode with outdated @nestjs/microservices types
fix
Cast to any: (this.grpcClient as any).getService('HelloService') or update types.
Upgrade
Version history
0.1.8latest on npm
Audit
Dependencies
@nestjs/microservicesrequiredProvides ClientGrpcProxy and Transport enum used by the module
@nestjs/commonrequiredPeer dependency for NestJS decorators and module system
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
nestjs-grpc-client — npm install nestjs-grpc-client · libregistry