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

pinary

v1.4.4

Published

RPC other TCP/TLS and PubSub

Downloads

21

Readme

pinary


Node.js CI npm version MIT Licence Dependency Status

Introduction

Yet another RPC client and server, with minimalistic publish/subscribe implementation.

  • Server

    • TCP or TLS, as you want (TLS require certificates, see https://github.com/jfromaniello/selfsigned )
    • Persistant connection
    • Binary frames (fast)
    • Optional ZLIB compression
    • Minimalistic JSON Schema implementation (input integrity)
    • Handle Max Clients
    • Basic publish/subscribe support
  • Client

    • Automatic reconnect
    • Internal RPC calls queue
      • Allow lazy client connect
      • Store calls when not connected and play calls when reconnect

Install

npm install pinary

Server

Server: instantiation

const PinaryServer = require('pinary').server;
const server = new PinaryServer();

// with options (see below)
// const server = new PinaryServer({port:64000});

| Option | Default | Notes
|-----------------------|-------------------------------|---------------- | useTLS | false | Use clear TCP or TLS
| useZLIB | false | Use ZLIB compression | maxClients (1) | 10 | Maximum number of simultaneous TCP connections | timeoutData | 1000 | Delay before socket close if no data sent, in milliseconds | host | 0.0.0.0 | Listening IP/host | port | 65000 for TCP, 65001 for TLS | Listening port | key | null | TLS: private key | cert | null | TLS: public key | ca | null | TLS: certificate authority (string of array of string) | secureProtocol | TLSv1_2_method | TLS: cipher | rejectUnauthorized | false | TLS: allow self signed certificates, or not

(1) under the hood, a "client" is in fact 2 sockets, one for writing, one for reading.

Client

Client: instantiation

const PinaryClient = require('pinary').client;
const client = new PinaryClient(); // auto connect

// with a TCP url
// const client = new PinaryClient('tcp://localhost:64000',[options]);

// with a TLS url
// const client = new PinaryClient('tls://localhost:64000',[options]);

| Option | Default | Note |
|---------------------------------------|-------------------------------|------| | reconnectInterval | 500 | milliseconds | | queueSize | 100 | store rpc calls limit when not connected/disconnected |

Client: trigger a method

// using callback
client.rpc('myMethod', (err, result) => {
    if (err) throw err;
    console.log(result);
});

// using async/await
async function letsgo() {
    let result;
    try {
        result = await client.rpcPromise('myMethod');
    } catch(e) {
        // something wrong
    }
    console.log(result);
}

Note: if not yet connected or while the client is trying to reconnect, RPC calls are stored in a queue and played when client is connected.

Client: events

| event name | arguments | Notes
|-----------------------|-------------------------------|---------------- | connected | retryCount | if retryCount = 0, first connection, else reconnection
| disconnected | | | error | Error |

Publish/Subscribe (PUBSUB)

Client to clients

const Server = require('pinary').server;
const Client = require('pinary').client;

const server = new Server();
const client1 = new Client();
const client2 = new Client();

const channel = '/myChannel';

server.start();

client1.subscribe('/bla', (data) => {
    console.log(data);
    process.exit();
});

client2.publish('/bla', { foo:'bar' });

Server to clients

const Server = require('pinary').server;
const Client = require('pinary').client;

const server = new Server();
const client = new Client();

const channel = '/myChannel';

server.start();

client.subscribe(channel, (data) => {
    console.log(data);
    process.exit();
});

server.publish(channel, { foo:'bar' });

The actual implementation is minimalistic:

  • a channel is considered as an ID, you cannot use wildcards like redis or faye

TODO

  • finish doc
    • events emitted (server)
    • server methods registration (see test/tests/102.methodExist.js, or examples/ for moment)