Need help with znode?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

mikeal
197 Stars 12 Forks 20 Commits 4 Opened issues

Description

Bi-directional RPC through any stream.

Services available

!
?

Need anything else?

Contributors list

# 3,826
JavaScr...
node
js
hapi
16 commits
# 74,172
Shell
fp
Node.js
Perl
1 commit
# 3,829
React N...
Objecti...
JavaScr...
React
1 commit

znode

znode is a remote method execution library for Node.js and the browser.

  • Bi-directional RPC over any stream (WebRTC, WebSockets, TCP, etc)
  • Supports binary types natively without serializing to strings. [1]
  • Simple API using async await.
  • Supports RPC methods returning additional RPC methods.

[1] Underlying implementation uses msgpack5. Performance is optimized for binary type usage (JSON would be faster for cases other than binary types).

Full Usage

const RPC = {
  /* basic method support */
  ping: () => 'pong',
  /* async methods work identicaly to sync methods */
  ping2: async () => 'pong2',
  /* supports binary types */
  pingBuffer: () => Buffer.from('pong'),
  /* you can also add static properties */
  API: 'v1'
}

net.createServer(async socket => { let remote = await znode(socket, RPC)

let concater = await remote.createConcat('pre-') console.log(await concater.concat('post')) // priv-pre-post }) .listen(async () => {

const dynamicRPC = { createConcat: str => { let _private = 'priv-' return {concat: _str => _private + str + _str} } }

let socket = net.connect(port) let remote = await znode(socket, dynamicRPC) console.log(await remote.ping()) // pong console.log(await remote.ping2()) // pong2 console.log(await remote.pingBuffer()) // console.log(remote.API) // v1 })

RPC methods can return anything that can be serialized by msgpack5. RPC methods can also return objects with additional methods that will be turned into additional remote methods.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.