Skip to content

Files

Latest commit

e5b58da · Feb 28, 2024

History

History

grpc-proto-loader

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 11, 2020
Jul 29, 2022
Oct 11, 2020
Sep 21, 2020
Nov 16, 2020
Sep 21, 2020
May 14, 2021
Feb 28, 2024
Jul 30, 2022
Jul 29, 2022
Feb 28, 2024
Sep 21, 2020

grpc-proto-loader example

This example shows how to use @grpc/proto-loader & @grpc/grpc-js to build a fully typed CLI application that runs on Node.js.

@grpc/proto-loader to used to generate the types, as well as load the protobuf files at runtime using protobuf.js instead of google-protobuf.

No proto compiler is used. It's all JavaScript.

App layout

Generating the Types

Install dependencies:

npm install

Use @grpc/proto-loader to generate the TypeScript files:

$(npm bin)/proto-loader-gen-types --longs=String --enums=String --defaults --oneofs --grpcLib=@grpc/grpc-js --outDir=proto/ proto/*.proto

This is aliased as a npm script:

npm run build:proto

Running the App

This simple app demonstrates the different gRPC calls you can perform.

First generated the types and build the application files:

npm run build

Start the server:

npm run start:server

Now run the client by specifying which example you want to run:

npm run start:client -- --unary
npm run start:client -- --server-streaming
npm run start:client -- --client-streaming
npm run start:client -- --bidi-streaming