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

gelrpc

v1.0.0

Published

GelRpc for Node.js

Downloads

4

Readme

GelRpc for Node.js

GelRpc is a dead simple (~300 loc) rpc system that works over any full-duplex text/byte/json stream. It has one dependency - through. Matching libraries for Python and .NET are planned.

Table of Contents

Usage

var gelrpc = require('gelrpc');

// Create a server, that answers questions.
// Pass in functions that may be called remotely. (Alternatively, 
// you may pass a route function to gelrpc.stream.)
var server = gelrpc.stream({
  hello: function(name, cb) {
    cb(null, 'hello, ' + name);
  }
});

// Create a client, that asks questions.
var client = gelrpc.stream();

// Pipe them together!
client.pipe(server).pipe(client);

// Make a call without further ado.
client.rpc('hello', ['JIM'], function (err, message) {
  if (err)
    console.log('ERROR: ' + err);
  else if (message === 'hello, JIM')
    console.log('Got the message!');
});

// Or create a remote facade to call with.
var remote = client.wrap(['hello']);
remote.hello('JIM', function (err, mess) {
  if (err)
    console.log('ERROR: ' + err);
  else if (message === 'hello, JIM')
    console.log('Got the message!');
})

Over TCP

Server

net.createServer(function(con) {
  // Create one server per connection.
  var server = gelrpc.stream(/* ... */);
  server.pipe(con).pipe(server);
}).listen(3000));

Client

var client = gelrpc.stream();
var con = net.connect(3000);
client.pipe(con).pipe(client);

var remote = client.wrap(['hola']);
remote.hola('steve', function(err, res) {
  console.log(res);
});

API Reference

gelrpc.router

Documentation for gelrpc.router will be coming shortly.

gelrpc.serializer

Documentation for gelrpc.serializer will be coming shortly.

gelrpc.stream(route, opts)

Returns a Stream that will call methods when written to.

Parameters

  • [route] Object - contains one key per callable function.
  • [route] Function - accepts (path, args, callback) where path is a string, args any type and callback a standard Node.js error-first callback function.
  • [opts] Object - contains one or more of the following options.
    • [EOL] String - end of line marker to use. Default: '\n'.
    • [flattenError] Function - accepts (err) and returns an object to serialize.
    • [prefix] String - a value to use as an include-filter for each EOL-separated line in the stream.
    • [raw] Boolean - when true, the default serializer which uses JSON.stringify is disabled and you just get a stream of objects. Use this if you want to do your own parsing and serializing.

Class: Stream

A class that is derived from Stream.

stream.wrap(methodNames)

Returns a wrapped object with the remote's methods. The client needs to already know the names of the methods. Accepts a string, and array of strings, or a object. If it's an object, wrap will use the keys as the method names.

Example

// Create rpc stream around the fs module.
var fsrpc = gelrpc.stream(require('fs'));
// pipe, etc

Then, in another process...

var fsrpc = gelrpc.stream();
// pipe, etc

// wrap, with the right method names.
var remoteFs = fsrpc.wrap(require('fs'));

remoteFs.mkdir('/tmp/whatever', function (err, dir) {
  // yay!
})

Now, the second process can call the fs module in the first process! wrap does not use the methods for anything. It just wants the names.

stream.rpc(name, args, cb)

Directly send a call to the remote side without any wrapper function.

Parameters

  • name String - name (or 'path/to/name') of a remote function.
  • [args] Any - array of arguments to pass to the remote function.
  • [cb] Function - a standard Node.js error-first callback that will be called when the remote side responds.

Example

var client = gelrpc.stream();
client.rpc('hello', [name], callback);
// Another way of sending the same remote call is by using a 
// wrapper function: 
client.wrap('hello').hello(name, callback);

stream.pipe(stream)

Read about piping streams here.

Ports

(Coming Soon!)

...

Credits

This project contains a fork of Dominic Tarr's excellent rpc-stream and stream-serializer libraries, which form the core of this library. Thanks for your work!

WTF?

(Why the Fork?)

I needed a single, tightly-coupled library that I can easily maintain instead of multiple loosely-coupled libraries that I don't control. This library will also be used in a larger library that it must be compatible with.