-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.js
More file actions
30 lines (24 loc) · 1019 Bytes
/
client.js
File metadata and controls
30 lines (24 loc) · 1019 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
/* ----------------------------------------------------------------------
This client handles the communication to the express from the grpc server
-------------------------------------------------------------------------*/
const PROTO_PATH = __dirname + "/protos/employee.proto";
const grpc = require("grpc");
const protoLoader = require("@grpc/proto-loader");
const _ = require("lodash");
// PackageDefinition used for generating code from the proto file using protocal buffer compiler
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
enums: String,
longs: String,
defaults: true,
oneofs: true,
});
const employee_proto = grpc.loadPackageDefinition(packageDefinition).employee;
// Creating client and binding to the port of the grpc server for communcation
// this client holds every function inside employee package
let client = new employee_proto.Employee(
"localhost:3001",
grpc.credentials.createInsecure()
);
// exporting for using on api
module.exports = client;