Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nice-grpc

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nice-grpc

A Node.js gRPC library that is nice to you

  • 1.0.6
  • npm
  • Socket score

Version published
Weekly downloads
134K
decreased by-1.23%
Maintainers
1
Weekly downloads
 
Created

What is nice-grpc?

The nice-grpc package is a modern, easy-to-use gRPC library for Node.js. It provides a more ergonomic API compared to the official gRPC library, with features like middleware support, automatic retries, and better TypeScript support.

What are nice-grpc's main functionalities?

Creating a gRPC Server

This code demonstrates how to create a gRPC server using nice-grpc. The server listens on port 50051 and implements a simple Greeter service that responds with a greeting message.

const { createServer } = require('nice-grpc');
const { GreeterService } = require('./proto/greeter_grpc_pb');

const server = createServer();

server.add(GreeterService, {
  async sayHello(request) {
    return { message: `Hello, ${request.name}!` };
  },
});

server.listen('0.0.0.0:50051');

Creating a gRPC Client

This code demonstrates how to create a gRPC client using nice-grpc. The client connects to a server running on localhost:50051 and calls the sayHello method of the Greeter service.

const { createChannel, createClient } = require('nice-grpc');
const { GreeterClient } = require('./proto/greeter_grpc_pb');

const channel = createChannel('localhost:50051');
const client = createClient(GreeterClient, channel);

async function main() {
  const response = await client.sayHello({ name: 'World' });
  console.log(response.message);
}

main();

Using Middleware

This code demonstrates how to use middleware in nice-grpc. The loggingMiddleware logs the request and response of each gRPC call. The middleware is added to the server using the use method.

const { createServer, createChannel, createClient, Metadata } = require('nice-grpc');
const { GreeterService, GreeterClient } = require('./proto/greeter_grpc_pb');

const loggingMiddleware = async (call, context, next) => {
  console.log('Request:', call.request);
  const response = await next(call, context);
  console.log('Response:', response);
  return response;
};

const server = createServer().use(loggingMiddleware);

server.add(GreeterService, {
  async sayHello(request) {
    return { message: `Hello, ${request.name}!` };
  },
});

server.listen('0.0.0.0:50051');

Other packages similar to nice-grpc

Keywords

FAQs

Package last updated on 16 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc