How to communicate gRPC example working with Node.js?

0 votes

Hi Guys,

I am working as a Node.js developer. I am trying to understand how to communicate with a gRPC server. It seems I have to load any .proto files you provided and load protoDescriptor to work with the client. 

Actually, with the example below am not able to load proto files because proto-loader mess up with Google APIs importing.

var PROTO_PATH = __dirname + '/../protos/';

var grpc = require('grpc');
var protoLoader = require('@grpc/proto-loader');
console.log(PROTO_PATH);
var packageDefinition = protoLoader.loadSync(PROTO_PATH + 'internal.proto');
console.log(packageDefinition);
//PROTO_PATH);

//{keepCase: true,
// longs: String,
// enums: String,
// defaults: true,
// oneofs: true
//});
var protoDescriptor =  grpc.loadPackageDefinition(packageDefinition);
// The protoDescriptor object has the full package hierarchy
var api_proto = protoDescriptor.api;

console.log(api_proto);

function main() {
var client = new api_proto.InternalService('192.168.1.80:8080',
                                   grpc.credentials.createInsecure());
var body = JSON.stringify({ username: "admin", password: "password" })

client.Login({}, function(err, response) {
console.log('loginresponse:', response.message);
});
}

main();

Would be great if you can provide an example that can work with Lora-app-server gRPC.
 

Thanks & Regards
Camillelola

Dec 5, 2018 in Others by camillelola
• 140 points
217 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
1 answer

How do I start studying Node.JS to create a restful API?

Node.js is an open source server environment ...READ MORE

answered Jun 10 in Others by ArchanaNagur
• 2,110 points
25 views
0 votes
1 answer
0 votes
1 answer

Why and when to use Node.js?

The major reason why they are going ...READ MORE

answered Jun 14 in Others by sunshine
• 1,160 points

edited Jun 14 by sunshine 22 views
+1 vote
0 answers
0 votes
1 answer

How to check if array is multidimensional or not?

Since the 'second dimension' could be just ...READ MORE

answered Nov 5, 2018 in Others by DataKing99
• 8,100 points
121 views
0 votes
1 answer

How is machine learning used to detect objects?

To understand the surrounding environment in real ...READ MORE

answered Nov 30, 2018 in Others by Kailash
49 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
104 views
0 votes
1 answer
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
56 views