Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
nice-grpc-common
Advanced tools
The nice-grpc-common package provides common utilities and types for building gRPC services with the nice-grpc framework. It simplifies the process of creating and managing gRPC services in Node.js, offering a more user-friendly API compared to the standard grpc package.
Creating a gRPC Service
This code demonstrates how to create a simple gRPC service using nice-grpc-common. The service has a single method, sayHello, which returns a greeting message.
const { createServer } = require('nice-grpc');
const { createServiceDefinition } = require('nice-grpc-common');
const serviceDefinition = createServiceDefinition({
sayHello: async (request) => {
return { message: `Hello, ${request.name}!` };
},
});
const server = createServer();
server.add(serviceDefinition);
server.listen('0.0.0.0:50051');
Client Interceptors
This code demonstrates how to create and use a client interceptor with nice-grpc-common. The interceptor logs the method being called before proceeding with the gRPC call.
const { createChannel, createClient } = require('nice-grpc');
const { createClientInterceptor } = require('nice-grpc-common');
const loggingInterceptor = createClientInterceptor(async (call, method, options) => {
console.log(`Calling method: ${method.path}`);
return call(method, options);
});
const channel = createChannel('localhost:50051');
const client = createClient(serviceDefinition, channel, { interceptors: [loggingInterceptor] });
client.sayHello({ name: 'World' }).then(response => {
console.log(response.message);
});
Server Interceptors
This code demonstrates how to create and use a server interceptor with nice-grpc-common. The interceptor logs the method being called before proceeding with the gRPC call.
const { createServer } = require('nice-grpc');
const { createServerInterceptor } = require('nice-grpc-common');
const loggingInterceptor = createServerInterceptor(async (call, method, options) => {
console.log(`Received call to method: ${method.path}`);
return call(method, options);
});
const server = createServer({ interceptors: [loggingInterceptor] });
server.add(serviceDefinition);
server.listen('0.0.0.0:50051');
The grpc package is the official Node.js implementation of gRPC. It provides a comprehensive set of features for building gRPC services but has a more complex and less user-friendly API compared to nice-grpc-common.
@grpc/grpc-js is a pure JavaScript implementation of gRPC for Node.js. It offers similar functionality to the grpc package but is designed to be more compatible with modern JavaScript and TypeScript projects. It also has a more complex API compared to nice-grpc-common.
grpc-tools is a package that provides tools for working with gRPC in Node.js, including code generation from .proto files. It complements the grpc and @grpc/grpc-js packages but does not provide the same level of abstraction and ease of use as nice-grpc-common.
Common data structures and types for
nice-grpc
and nice-grpc-web
.
If you are making a middleware library, consider depending on
nice-grpc-common
, as it is considered more stable in terms of semver. Also,
this allows you to build an isomorphic client middleware (working on both
Node.js and the Browser).
For application code, use nice-grpc
or nice-grpc-web
directly. Both
re-export names from nice-grpc-common
.
npm install nice-grpc-common
Metadata
— represents
gRPC Metadata.Status
— enum with
gRPC status codes.CallContext
— call context passed to server
methods.ServerError
.ServerMiddleware
.composeServerMiddleware
.CallOptions
— call options accepted by client
methods.ClientError
.ClientMiddleware
.composeClientMiddleware
.FAQs
Common stuff for nice-grpc and nice-grpc-web
The npm package nice-grpc-common receives a total of 115,042 weekly downloads. As such, nice-grpc-common popularity was classified as popular.
We found that nice-grpc-common demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.