grpcgrpc-node

How to compile gRPC Proto files for Node?


The gRPC documentation describes how to use the protoc command line program to compile a *.proto file to a certain language for all languages except for Node.

There, it is only described (at the time of this writing) how to dynamically load and at runtime (behind the scenes) generate the JS code.

Is it possible to use the protoc program to compile proto files to JS directly, similar to other languages?


Solution

  • I've found how to do static code generation for Node on this GitHub page.

    Here's a copy of the example they provide:

    npm install -g grpc-tools
    grpc_tools_node_protoc --js_out=import_style=commonjs,binary:../node/static_codegen/ --grpc_out=../node/static_codegen --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` helloworld.proto
    grpc_tools_node_protoc --js_out=import_style=commonjs,binary:../node/static_codegen/route_guide/ --grpc_out=../node/static_codegen/route_guide/ --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` route_guide.proto