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
2,365 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 11, 2019 in Others by ArchanaNagur
• 2,360 points
979 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,360 points
869 views
0 votes
0 answers

How to get response from S3 getObject in Node.js?

I am attempting to get data back ...READ MORE

Apr 23, 2022 in Others by Kichu
• 19,040 points
1,863 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,300 points

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

How to split a number with coma betweeen two colunms

Jul 3, 2019 in Others by anonymous
842 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
1,916 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,445 views
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,360 points
1,577 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP