This project contain example that create microservice with gRPC + Typescript
- typescript
- @grpc/grpc-js
- google-protobuf
- grpc-tools
- grpc_tools_node_protoc_ts
To develop with typescript it is necessary to install the packages below. Because these packages are responsible for compiling and generating types that proto files.
$ yarn add -D @types/long grpc_tools_node_protoc_ts grpc-tools//package.json
"scripts": {
"compile": "grpc_tools_node_protoc --js_out=import_style=commonjs,binary:./proto --grpc_out=grpc_js:./proto -I ./proto ./proto/*.proto && grpc_tools_node_protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --ts_out=grpc_js:./proto -I ./proto ./proto/*.proto",
"dev:server": "ts-node-dev --transpile-only --inspect --ignore-watch node_modules server/src/index.ts",
"dev:client": "ts-node-dev --transpile-only --inspect --ignore-watch node_modules client/src/index.ts"
}Install dependencies
$ yarn Up Server
$ yarn dev:serverUp Client
$ yarn dev:clientLucas Santos - O guia completo do gRPC parte 3: Tipos em tudo com TypeScript!