3 A utility package for loading `.proto` files for use with gRPC, using the latest Protobuf.js package.
4 Please refer to [protobuf.js' documentation](https://github.com/dcodeIO/protobuf.js/blob/master/README.md)
5 to understands its features and limitations.
10 npm install @grpc/proto-loader
16 const protoLoader = require('@grpc/proto-loader');
17 const grpcLibrary = require('grpc');
19 const grpcLibrary = require('@grpc/grpc-js');
21 protoLoader.load(protoFileName, options).then(packageDefinition => {
22 const packageObject = grpcLibrary.loadPackageDefinition(packageDefinition);
25 const packageDefinition = protoLoader.loadSync(protoFileName, options);
26 const packageObject = grpcLibrary.loadPackageDefinition(packageDefinition);
29 The options parameter is an object that can have the following optional properties:
31 | Field name | Valid values | Description
32 |------------|--------------|------------
33 | `keepCase` | `true` or `false` | Preserve field names. The default is to change them to camel case.
34 | `longs` | `String` or `Number` | The type to use to represent `long` values. Defaults to a `Long` object type.
35 | `enums` | `String` | The type to use to represent `enum` values. Defaults to the numeric value.
36 | `bytes` | `Array` or `String` | The type to use to represent `bytes` values. Defaults to `Buffer`.
37 | `defaults` | `true` or `false` | Set default values on output objects. Defaults to `false`.
38 | `arrays` | `true` or `false` | Set empty arrays for missing array values even if `defaults` is `false` Defaults to `false`.
39 | `objects` | `true` or `false` | Set empty objects for missing object values even if `defaults` is `false` Defaults to `false`.
40 | `oneofs` | `true` or `false` | Set virtual oneof properties to the present field's name. Defaults to `false`.
41 | `includeDirs` | An array of strings | A list of search paths for imported `.proto` files.
43 The following options object closely approximates the existing behavior of `grpc.load`: