Giter Site home page Giter Site logo

znode's Introduction

znode

Coverage Status Build Status dependencies Status

semantic-release Commitizen friendly JavaScript Style Guide

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()) // <Buffer 70 6f 6e 67>
  console.log(remote.API) // v1
})

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

znode's People

Contributors

mikeal avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.