Appearance
Generating Stubs for JS ​
Step 1. Install Protocol Buffers Compiler ​
For Windows: ​
Download the latest version of
protocfor Windows from the official Google Protocol Buffers repository: https://github.com/protocolbuffers/protobuf/releases.Select the
protoc-<version>-win64.zipfile for the 64-bit Windows version and extract it to a convenient location (e.g.,C:\protoc).Add the
binfolder from the extracted archive to thePATHenvironment variable so thatprotoccan be called from any directory:
powershell
[System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\protoc\bin", [System.EnvironmentVariableTarget]::Machine)- Verify the
protocinstallation by running the command:
powershell
protoc --versionIf installed correctly, the protoc version will be displayed.
For Linux: ​
To install protoc on Linux, please follow the instructions provided on the official gRPC documentation site: https://grpc.io/docs/protoc-installation/. This guide includes steps for various distributions and provides the latest installation instructions.
Step 2. Install Additional Plugins for protoc ​
Install protoc-gen-js for generating JS files:
sh
npm install -g protoc-gen-jsInstall protoc-gen-grpc for generating gRPC files:
sh
npm install -g protoc-gen-grpcStep 3. Download .proto file for a Service ​
Download .proto file for a Service, using the following CLI command:
sh
snet service get-api-registry <org_id> <SERVICE_ID> <PROTO_DIR>For more details, please check the CLI or CLI Manual
Step 4. Generate stub files for JS ​
Navigate to the directory where the .proto file is located, and run the following commands to generate the necessary stub files:
- Navigate to the directory with the
.protofile:
sh
cd <PATH_TO_PROTO_DIR>- Generate JavaScript files:
sh
protoc -I="." --js_out=import_style=commonjs,binary:. <file_name>.proto- Generate gRPC files:
sh
protoc-gen-grpc -I="." --grpc_out=grpc_js:. <file_name>.protoThese commands will create JS and gRPC files required for the service.