npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kareemun_grpc

v1.2.0

Published

KgRPC is a Node.js package that simplifies the creation of gRPC servers. It provides easy-to-use methods for setting up and running gRPC servers with default configurations.

Downloads

5

Readme

Here's an updated version of the markdown documentation with implementation examples:


External Dependencies

  • grpc: gRPC library for Node.js. GitHub
  • protoLoader: gRPC Protocol Buffer (proto) loader for Node.js. GitHub
  • colors: Colors library for Node.js terminal output. GitHub

Server Class

Constructor

const server = new Server(configs);
  • Configs: Optional configurations for the server.

Methods

createInsecureServer
server.createInsecureServer(host, port, callback);
  • Host: The host address to bind the server to.
  • Port: The port number to bind the server to.
  • Callback: Callback function to be called after the server is bound (optional).
addService
server.addService(protoFile, protoMessagesPackage, serviceName, methods, protoLoadingOptions, callback);
  • ProtoFile: The path to the Protocol Buffers (protobuf) file.
  • ProtoMessagesPackage: The name of the protobuf messages package.
  • ServiceName: The name of the service in the protobuf file.
  • Methods: The service method definitions.
  • ProtoLoadingOptions: Options for loading the protobuf file (optional).
  • Callback: Callback function to be called after service addition (optional).

Client Class

Constructor

const client = new Client();

Methods

createInsecureConnection
client.createInsecureConnection(protoFile, protoMessagesPackage, serviceName, host, port, protoLoadingOptions, callback);
  • ProtoFile: The path to the Protocol Buffers (protobuf) file.
  • ProtoMessagesPackage: The name of the protobuf messages package.
  • ServiceName: The name of the service in the protobuf file.
  • Host: The host address of the gRPC server.
  • Port: The port number of the gRPC server.
  • ProtoLoadingOptions: Options for loading the protobuf file (optional).
  • Callback: Callback function to be called after connection establishment (optional).
callServer
client.callServer(methodName, message, callback);
  • MethodName: The name of the RPC method to call.
  • Message: The request message to send.
  • Callback: Callback function to handle the response (optional).

Implementation Examples

Creating a gRPC Server

const { Server } = require('./path/to/Server');

const server = new Server();

const host = 'localhost';
const port = 50051;

server.createInsecureServer(host, port, (err, boundPort) => {
    if (err) {
        console.error('Failed to start gRPC server:', err);
    } else {
        console.log(`gRPC server started successfully on port ${boundPort}`);
    }
});

Adding a Service to the Server

const { Server } = require('./path/to/Server');

const server = new Server();

const protoFile = './path/to/protofile.proto';
const protoMessagesPackage = 'packageName';
const serviceName = 'ServiceName';
const methods = { /* Define your service methods here */ };

server.addService(protoFile, protoMessagesPackage, serviceName, methods);

Creating a gRPC Client

const { Client } = require('./path/to/Client');

const client = new Client();

const protoFile = './path/to/protofile.proto';
const protoMessagesPackage = 'packageName';
const serviceName = 'ServiceName';
const host = 'localhost';
const port = 50051;

client.createInsecureConnection(protoFile, protoMessagesPackage, serviceName, host, port, (serverAddress) => {
    console.log(`Connected to gRPC server at ${serverAddress}`);
});

Making RPC Calls with the Client

const { Client } = require('./path/to/Client');

const client = new Client();

const methodName = 'MethodName';
const message = { /* Your request message here */ };

client.callServer(methodName, message, (error, response) => {
    if (error) {
        console.error('RPC call failed:', error);
    } else {
        console.log('RPC call successful. Response:', response);
    }
});

This code provides a simple interface for creating gRPC servers and clients in Node.js, allowing for easy integration with Protocol Buffers (protobuf) files. The implementation examples demonstrate how to use the provided classes to set up and interact with gRPC services.