https://github.com/nersent/grpc-nest
https://github.com/nersent/grpc-nest
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nersent/grpc-nest
- Owner: nersent
- License: mit
- Created: 2023-07-19T18:55:04.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-20T13:58:47.000Z (almost 2 years ago)
- Last Synced: 2025-02-07T19:16:33.934Z (4 months ago)
- Language: JavaScript
- Size: 114 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ☁️ grpc-nest
Type-safe thin wraper around [grpc-js](https://github.com/grpc/grpc-node) for [Nest.js](https://github.com/nestjs/nest) with support for promises.
> Note: This library is in an early development stage. Expect breaking changes.
## Installation
```bash
yarn add @nersent/grpc-nest
```## [Example](/example/)
## Quick Start
### 1. Compile proto
```bash
yarn grpc-nest ./example/*.proto ./example/generated
```### 2.
`index.ts`
```ts
import { createGrpcTransport } from '@nersent/grpc-nest';const app = await NestFactory.create(AppModule);
app.connectMicroservice(
createGrpcTransport({ address: "0.0.0.0:4269" }, app),
);await app.startAllMicroservices();
````app_module.ts`
```ts
import { GrpcModule } from '@nersent/grpc-nest';@Module({
imports: [GrpcModule],
controllers: [ApiController]
})
export class AppModule {}
````api_controller.ts`
```ts
import {
IExampleApiService,
ExampleApiService,
} from "./generated/example_grpc_pb";
import {
ExampleApiStatusRequest,
ExampleApiStatusResponse,
} from "./generated/example_pb";@GrpcController(ExampleApiService)
export class ApiController implements IGrpcController {
public async status(
req: ExampleApiStatusRequest,
): Promise {
const name = req.getName();
const res = new ExampleApiStatusResponse();
res.setMessage(name);
return res;
}
}
```
---Made by [Nersent](https://nersent.com)