grpc-client-promise-wrapper
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

grpc-client-promise-wrapper

Documentation

Use async/await for @grpc/grpc-js package

Installation

$ npm install grpc-client-promise-wrapper

Javascript

const promiseWrapper = require('grpc-client-promise-wrapper');

Typescript

import * as promiseWrapper from 'grpc-client-promise-wrapper';

Example

  • test.proto
syntax = "proto3";

package test;

service TestService {
  rpc GetTestFn (inputParam) returns (returnValue);
}

message InputParam {
  string inputParam = 1;
}

message ReturnValue {
  string returnValue = 1;
}
  • app.js
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const promiseWrapper = require('grpc-client-promise-wrapper');

const testStub = () => {
  const packageDefinition = protoLoader.loadSync(path.join(__dirname, './test.proto'));
  const testService = grpc.loadPackageDefinition(packageDefinition).test;
  return promiseWrapper(new testService.TestService('localhost:3001', grpc.credentials.createInsecure()));
};

const getTestFn = async (params) => {
  return testStub().getTestFn(params);
};

License

MIT License

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i grpc-client-promise-wrapper

    Weekly Downloads

    6

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    3.91 kB

    Total Files

    5

    Last publish

    Collaborators

    • beoum