@nersent/grpc-nest
TypeScript icon, indicating that this package has built-in type declarations

1.2.0-dev.1 • Public • Published

☁️ grpc-nest

Type-safe thin wraper around grpc-js for Nest.js with support for promises.

Note: This library is in an early development stage. Expect breaking changes.

Installation

yarn add @nersent/grpc-nest

Example

Quick Start

1. Compile proto

yarn grpc-nest ./example/*.proto ./example/generated

2.

index.ts

import { createGrpcTransport } from '@nersent/grpc-nest'; 

const app = await NestFactory.create(AppModule);

app.connectMicroservice<MicroserviceOptions>(
  createGrpcTransport({ address: "0.0.0.0:4269" }, app),
);

await app.startAllMicroservices();

app_module.ts

import { GrpcModule } from '@nersent/grpc-nest';

@Module({
  imports: [GrpcModule],
  controllers: [ApiController]
})
export class AppModule {}

api_controller.ts

import {
  IExampleApiService,
  ExampleApiService,
} from "./generated/example_grpc_pb";
import {
  ExampleApiStatusRequest,
  ExampleApiStatusResponse,
} from "./generated/example_pb";

@GrpcController(ExampleApiService)
export class ApiController implements IGrpcController<IExampleApiService> {
  public async status(
    req: ExampleApiStatusRequest,
  ): Promise<ExampleApiStatusResponse> {
    const name = req.getName();
    const res = new ExampleApiStatusResponse();
    res.setMessage(name);
    return res;
  }
}

Made by Nersent

Readme

Keywords

none

Package Sidebar

Install

npm i @nersent/grpc-nest

Homepage

nersent.com

Weekly Downloads

3

Version

1.2.0-dev.1

License

MIT

Unpacked Size

196 kB

Total Files

29

Last publish

Collaborators

  • xnerhu
  • sential