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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thzero/library_server_service_grpc

v0.19.1

Published

![GitHub package.json version](https://img.shields.io/github/package-json/v/thzero/library_server_service_grpc) ![David](https://img.shields.io/david/thzero/library_server_service_grpc) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)

Downloads

229

Readme

GitHub package.json version David License: MIT

library_server_service_grpc

gRPC client and server bases for @thzero/library_server, built on @grpc/grpc-js.

For service-to-service calls inside a deployment, alongside the REST communication service used for outward-facing traffic. Host resolution goes through the framework's service discovery when it is configured, and falls back to a configured base url when it is not.

Requirements

NodeJs

NodeJs version 22+

Installation

NPM

npm install @thzero/library_server_service_grpc

Peer dependencies

  • @thzero/library_common
  • @thzero/library_common_service
  • @thzero/library_server

What it provides

client.jsBaseClientGrpcService

| Method | Purpose | |---|---| | _execute(correlationId, func, client, request) | Calls a generated stub method as a promise, attaching the correlationId as gRPC metadata. | | _host(correlationId, key, opts) | Resolves the host for a backend. | | _hostFromConfig(correlationId, host, key, opts) | Resolves from config, consulting service discovery when enabled. Discovered hosts are cached per key. | | _hostFromResource(correlationId, host, resource, opts) | Builds address:port from a discovery resource, assembling a DNS name from label, namespace and local when present. | | _credentials(correlationId) | Returns the channel credentials. Insecure by default — override this for anything crossing a trust boundary. |

_host takes the url straight from opts when one is supplied, prefers opts.resource over it, and only falls back to config when opts is absent entirely. Note that opts carrying neither a resource nor a url yields an empty host rather than the config fallback.

Every call sends correlationId as metadata, so a request can be traced across service boundaries the same way it is over HTTP.

server.jsBaseServerGrpcService

| Method | Purpose | |---|---| | _initServices(grpc) | Override this. Add your generated service implementations to the server. | | _start(correlationId) | Binds to 0.0.0.0:<grpc.port> and starts. Called during init. | | _correlationId(call) | Reads the correlationId from the call metadata. | | _authenticate(call) | Reads the authorization metadata and returns the correlationId. | | _handleError(correlationId, err, callback) | Turns an error into the { message } shape a gRPC callback expects, combining name and message. |

_authenticate does not currently reject anything — the authorization metadata is read and logged, but the validity check is a TODO in the source. Do not rely on it as a security boundary; override it, or authenticate at another layer.

Configuration

Server

{
    "app": {
        "grpc": {
            "port": 50051
        }
    }
}

A missing grpc block or grpc.port fails at boot.

Client

Per-backend, read through _config.getBackend(correlationId, key):

{
    "app": {
        "backend": {
            "<key>": {
                "baseUrl": "service-host:50051",
                "discoverable": {
                    "name": "<discovery service name>",
                    "enabled": true
                }
            }
        }
    }
}
  • baseUrl — used directly when discovery is off or unavailable.
  • discoverable — omit it to skip discovery entirely. With it present, discovery is used only when a SERVICE_DISCOVERY_RESOURCES service is registered and discoverable.enabled is not false.
  • discoverable.name — the name looked up in discovery. Required once discovery is active.

Wiring it up

import BaseClientGrpcService from '@thzero/library_server_service_grpc/client.js';

class InventoryClientService extends BaseClientGrpcService {
    async fetch(correlationId, id) {
        const host = await this._host(correlationId, 'inventory');
        const client = new InventoryClient(host.url, this._credentials(correlationId));
        return await this._execute(correlationId, client.fetch, client, { id });
    }
}

Register client and server services with the injector from _initServices in your BootMain derived class, or from a boot plugin's initServices. The client resolves SERVICE_DISCOVERY_RESOURCES during init, which may legitimately be absent.

Development

npm run lint       # eslint .
npm run lint:fix   # eslint . --fix
npm test           # node --test "test/*.test.js"