-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
31 lines (27 loc) · 878 Bytes
/
client.js
File metadata and controls
31 lines (27 loc) · 878 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
const grpc = require("@grpc/grpc-js")
const protoLoader = require("@grpc/proto-loader")
const packageDef = protoLoader.loadSync("todo.proto", {})
const grpcObject = grpc.loadPackageDefinition(packageDef)
const todoPackage = grpcObject.todoPackage;
const client = new todoPackage.Todo("0.0.0.0:4000", grpc.credentials.createInsecure())
client.createTodo({
"id": -1,
"text": "Laundry"
}, (_, response) => {
console.log("Todo Created :" + JSON.stringify(response))
})
// client.readTodos({}, (err, res) => {
// if (err) {
// console.log("Error: ", err)
// } else {
// console.log("TODO(s): ", res)
// }
// })
const call = client.readTodosStream();
call.on("data", item => {
console.log("Received item from server ", JSON.stringify(item))
})
call.on('end', (e) => {
if (e) console.log("Error in streaming data: ", e)
console.log("End of stream!")
})