# zerorpc

> A port of ZeroRPC to node.js

Latest version **0.9.8** (published 2018-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install zerorpc
pnpm add zerorpc
yarn add zerorpc
bun add zerorpc
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.8 |
| Published | 2018-08-22 |
| First published | 2012-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 63.3 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 710 |
| Author | François-Xavier Bourlet |
| Maintainers | bombela, shin |
| Keywords | zerorpc, rpc, distributed, communication |

## Links

- npm: https://www.npmjs.com/package/zerorpc
- Repository: https://github.com/0rpc/zerorpc-node
- Homepage: https://github.com/0rpc/zerorpc-node#readme
- Issues: https://github.com/0rpc/zerorpc-node/issues
- npm.io page: https://npm.io/package/zerorpc

## Dependencies (4)

- [uuid](https://npm.io/package/uuid.md) ^3.0.0
- [zeromq](https://npm.io/package/zeromq.md) ^4.6.0
- [underscore](https://npm.io/package/underscore.md) 1.3.3
- [msgpack-lite](https://npm.io/package/msgpack-lite.md) ^0.1.26

## Recent versions

- 0.9.8 (latest) — 2018-08-22
- 0.9.7 — 2017-01-31
- 0.9.6 — 2015-10-11
- 0.9.5 — 2015-06-05
- 0.9.4 — 2015-05-19
- 0.9.3 — 2013-05-16
- 0.9.2 — 2013-03-24
- 0.9.1 — 2012-08-24
- 0.9.0 — 2012-07-11
- 0.8.8 — 2012-07-11
- 0.8.7 — 2012-07-06
- 0.8.6 — 2012-07-05
- 0.8.5 — 2012-07-05
- 0.8.4 — 2012-07-02
- 0.8.3 — 2012-06-28
- … 15 more at https://npm.io/package/zerorpc/versions

## README

zerorpc-node
============

[![Build Status](https://travis-ci.org/0rpc/zerorpc-node.svg?branch=master)](https://travis-ci.org/0rpc/zerorpc-node)

ZeroRPC is a communication layer for distributed systems. zerorpc-node is a port of the original [ZeroRPC](https://github.com/0rpc/zerorpc-python) for node.js. We have full client and server support for version 3 of the protocol, and clients/servers written in the Python version can communicate transparently with those written in node.js. This project is in alpha.

To install the package:

Make sure you have [ZeroMQ](https://github.com/zeromq/libzmq) installed.

Then:

```bash
npm install zerorpc
```

If you get the error `Package libzmq was not found` after making sure ZeroMQ is installed, take a look at [the fix for zeromq.node](https://github.com/JustinTulloss/zeromq.node/issues/55). If you get the error `Unable to load shared library <<path to zeromq.node>>/binding.node`, [make sure you run ldconfig](https://github.com/JustinTulloss/zeromq.node/issues/85). If that still doesn't work, check out [this ticket](https://github.com/JustinTulloss/zeromq.node/issues/92).

Servers
-------

To create a new server:

```js
var zerorpc = require("zerorpc");
var server = new zerorpc.Server(context [, heartbeat]);
```

The constructor takes in a context object with the functions to expose
over RPC. Only functions that do not have a leading underscore will be
exposed. Each exposed method must take in a callback as the last
argument. This callback is called as `callback(error, response, more)`
when there is a new update, where error is an error object or string,
response is the new update, and more is a boolean specifying whether new
updates will be available later. `error`, `response`, and `more` default
to falsy values, so e.g. simply calling `callback()` closes an open
stream, since `more` is false by default. Constructor also takes a
heartbeat parameter that specifies the interval that the server should
ping clinets to let them know it is active.

Events:

* `error` - When an error occurs.

Methods:

* `bind(endpoint)` - Binds the server to the specified ZeroMQ endpoint.
* `connect(endpoint)` - Connects the server to the specified ZeroMQ endpoint.
* `close()` - Closes the ZeroMQ socket.

Full example:

```js
var zerorpc = require("zerorpc");

var server = new zerorpc.Server({
    addMan: function(sentence, reply) {
        reply(null, sentence + ", man!");
    },

    add42: function(n, reply) {
        reply(null, n + 42);
    },

    iter: function(from, to, step, reply) {
        for(i=from; i<to; i+=step) {
            reply(null, i, true);
        }

        reply();
    }
});

server.bind("tcp://0.0.0.0:4242");

server.on("error", function(error) {
    console.error("RPC server error:", error);
});
```

Clients
-------

To create a new client:

```js
var zerorpc = require("zerorpc");
var client = new zerorpc.Client(options);
```

The constructor optionally takes in an options object. Allowable options:

* `timeout` (number) - Sets the number of seconds to wait for a response before considering the call timed out. Defaults to 30.
* `heartbeatInterval` (number) - Sets the number of miliseconds to send send heartbeats to connected servers. Defaults to 5000ms.

Events:

* `error` - When an error occurs.

Methods:

* `bind(endpoint)` - Binds the client to the specified ZeroMQ endpoint.
* `connect(endpoint)` - Connects the client to the specified ZeroMQ endpoint.
* `close()` - Closes the ZeroMQ socket.
* `invoke(method, arguments..., callback)` - Invokes a remote method.
  * `method` is the method name.
  * `arguments` are a list of arguments passed to the method, if there are no arguments then this argument is ommitted
  * `callback` is a method to call when there is an update. This callback is called as `callback(error, response, more)`, where error is an error object, response is the new update, and more is a boolean specifying whether new updates will be available later (i.e. whether the response is streaming).

Full example:

```js
var zerorpc = require("zerorpc");

var client = new zerorpc.Client();
client.connect("tcp://127.0.0.1:4242");

client.on("error", function(error) {
    console.error("RPC client error:", error);
});

client.invoke("iter", 10, 20, 2, function(error, res, more) {
    if(error) {
        console.error(error);
    } else {
        console.log("UPDATE:", res);
    }

    if(!more) {
        console.log("Done.");
    }
});
```

---
_Source: https://npm.io/package/zerorpc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
