-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
36 lines (30 loc) · 758 Bytes
/
client.js
File metadata and controls
36 lines (30 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Load up dependencies
const grpc = require("@grpc/grpc-js");
const protoLoader = require("@grpc/proto-loader");
// Path to proto file
const PROTO_FILE = "./service_def.proto";
// Options needed for loading Proto file
const options = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
// Load Proto File
const pkgDefs = protoLoader.loadSync(PROTO_FILE, options);
// Load Definition into gRPC
const DogService = grpc.loadPackageDefinition(pkgDefs).DogService;
// Create the Client
const client = new DogService(
"localhost:3500",
grpc.credentials.createInsecure()
);
// make a call to GetDog
client.GetDog({}, (error, dog) => {
if (error) {
console.log(error);
} else {
console.log(dog);
}
});