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
947 views

1 answer to this question.

0 votes

hi.. you can read below link, it is a good and simple example about GRPC

https://medium.com/@alfianlosari/building-grpc-service-server-note-crud-api-with-node-js-bcc5478d5bdb

answered Dec 2, 2019 by Narendra Reddy Dalli

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, 2019 in Others by ArchanaNagur
• 2,320 points
125 views
0 votes
1 answer

In order to learn Node.js, I should be familiar with which other technologies ?

I appreciate your decision, its the perfect ...READ MORE

answered Jul 31, 2019 in Others by ArchanaNagur
• 2,320 points
90 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, 2019 in Others by sunshine
• 1,260 points

edited Jun 14, 2019 by sunshine 130 views
+1 vote
0 answers

How to split a number with coma betweeen two colunms

Jul 3, 2019 in Others by anonymous
61 views
0 votes
1 answer

Why is MongoDB associated with Node.js?

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

answered Jul 18, 2019 in Others by ArchanaNagur
• 2,320 points
130 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,810 points
385 views
0 votes
1 answer
0 votes
1 answer

How to include/ install any library in node.js application program?

Node.js is server side runtime environment that ...READ MORE

answered Jul 26, 2019 in Others by ArchanaNagur
• 2,320 points
98 views