grpc.server

3.0.2 • Public • Published

grpc.server

a simple abstraction around grpc.Server


Build StatusCoverage StatusISC LicenseNodeJS

JavaScript Style Guide

api

const server = require('grpc.server')

  • server(an optional {})
    • address string with the format url:port
    • credentials can use credentials.createInsecure or with certificates through an object { key, server }, passed as a Buffer
    • metadata set metadata that can be used in all calls, an array with { key: value }

methods

  • addServices(an array with the services object)
    • package proto package name
    • name service name
    • proto proto file
    • methods an object with the methods
  • start(callback function)
  • stop(callback function)

note: you can use unary, stream or bidirecional since the comm type should be handled on the proto files and in the methods

example

const server = require('grpc.server')
 
// proto file
/*
syntax = "proto3";
 
package helloWorld;
 
// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc sayHello (HelloRequest) returns (HelloReply) {}
}
 
// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}
 
// The response message containing the greetings
message HelloReply {
  string message = 1;
}
*/
 
const serverA = server()
 
const services = [
  {
    proto: protos.helloWorld,
    package: 'helloWorld',
    name: 'Greeter',
    methods: { sayHello: sayHello }
  }
]
 
serverA.
  .addServices(services)
  .startc(cb)
 
 
// to stop the server
serverA.stop(cb)
 

ISC License (ISC)

Dependents (0)

Package Sidebar

Install

npm i grpc.server

Weekly Downloads

0

Version

3.0.2

License

ISC

Last publish

Collaborators

  • quim