Skip to content

Instantly share code, notes, and snippets.

@leleofg
Created September 11, 2020 00:47
Show Gist options
  • Save leleofg/60801e6df49ed12376a131d47338d599 to your computer and use it in GitHub Desktop.
Save leleofg/60801e6df49ed12376a131d47338d599 to your computer and use it in GitHub Desktop.
Client gRPC
const grpc = require("grpc");
const protoLoader = require("@grpc/proto-loader");
const PROTO_PATH = __dirname + "/proto/user.proto";
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
defaults: true,
oneofs: true,
});
const protos = grpc.loadPackageDefinition(packageDefinition);
function main() {
const client = new protos.UserService(
"localhost:50051",
grpc.credentials.createInsecure()
);
client.createUser(
{ email: "[email protected]", username: "leo", passsword: "123456" },
function (err, response) {
console.log("Response:", response);
}
);
client.getUserById({ id: 123 }, function (err, response) {
console.log("Response:", response);
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment