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

rpc-light

v0.1.1

Published

A lightweight RPC library for the browser and Node.js

Readme

rpc-light

A lightweight RPC library for Node.js and the browser

Installation

yarn add rpc-light
# OR
npm install rpc-light

Node.js RPC Server

The RPC server requires minimal setup. The rpcService() function accepts an object of sync or async methods you want to expose to the client and returns an express handler function. Compose this with your Express server and start it to handle RPCs.

Example:

const { rpcService } = require("rpc-light/server.js");
const express = require("express");

const app = express();

// These are methods you want to expose to the client. This structure can have
// arbitrarily deep nesting.
const exposedMethods = {
  greetingService: {
    greet(name, exclaim = false) {
      const punctuation = exclaim ? "!": "."
      const message = `Hello, ${name}` + punctuation;
      return {
        message,
      };
    },
  },
};

// choose any URL path you would like, just make sure your client sends requests
// to that URL
app.use("/rpc", rpcService(exposedMethods));

app.listen(8080);

It's now possible to invoke greetingService.greet("World", true) via a POST request to the URL /rpc passing a JSON object with path and args keys:

POST /rpc
{
  "path": ["greetingService", "greet"],
  "args": ["World", true]
}

Next, we'll use the included RPC client to do just this.

Proxy-based RPC Client

The proxy-based RPC client is intended for use in the browser, but doesn't rely on any browser-specific APIs. It has no embedded knowledge of the RPC server or any of its methods and doesn't require type definitions of any kind such as protocol buffers.

Instead, this proxy-based RPC client tracks the names of properties accessed as a path variable until we invoke one of these properties as a function, at which point it delegates to a handler function that you provide.

Example:

import { createService } from "rpc-light/client.js";
import axios from "axios"; // optional, use any transport you like

// (1) We first call `createService()`, providing a `callHandler` (see below).
const service = createService(callHandler);

// (2) Then, we are able to access an arbitrarily deep hierarchy of properties
// on the service. As we access a deeper property chain, the service tracks this
// path. This has no effect before we invoke a function call on one of these
// properties.
service.greetingService.greet; //=> path = ["greetingService", "greet"]

// (3) Whenever we invoke a function call, the `callHandler` provided to
// `createService()` is called with the provided arguments. Note that because
// this is remote communication, all function calls return a promise that must
// be `await`-ed or `then()`-ed.
const response = await service.greetingService.greet("World", true);
console.log(response); //=> { message: "Hello, World!" }

// (4) The provided `callHandler()` is invoked with:
//  - `this` set to the proxy object (which contains the sequence of properties
//    accessed on its `path` key)
//  - all arguments passed as function parameters
async function callHandler(...args) {
  const { path } = this;
  const payload = { path, args };
  // (5) Finally, you issue server call here via fetch(), axios(), etc. The way
  // `rpc-light`'s server expects the call to be made is as follows, but if you
  // want to use your own custom server logic, you can do anything you want
  // here. (And the endpoint can be anything you configure on your server, it
  // doesn't need to be `/rpc` to work with `rpc-light`'s server.)
  return await axios.post("/rpc", payload).then(res => res.data);
}

Credits

Inspired by wildcard-api