Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including msg-fabric-core with all npm packages installed. Try it out:

var msgFabricCore = require("msg-fabric-core")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

msg-fabric-core v0.7.6

Distributed live object messaging. (Core)


msg-fabric-core is a uniform messaging API for writing distributed (network) actors.

In a browser environment, use msg-fabric-core to communicate in the main context, an IFrame, a Web Worker, over an RTCDataChannel, or over a WebSocket.

In a NodeJS environment, communciate over TCP, TLS, duplex Streams, WebSockets, or use a plugin to bridge over NATS or MQTT.

Sent packets are synchronously cloned, thereby preventing accidental mutation. Furthermore, packets are only encoded to bytes when needed to transmit across a stream-oriented connection — WebSocket, RTCDataChannel, TCP/TLS, or similar stream.

A collection of ES6 modules are published for both NodeJS and Web platforms, as well as all the core plugins, to allow crafting a build including only is required to solve the problem at hand.

Inspired by:


import FabricHub from 'msg-fabric-core' 
const hub = FabricHub.create()
Add a Target
const tgt_addr = hub.local.addTarget(pkt => {
  console.log('pkt target received pkt:', pkt)

  if (pkt.body.id_reply) {
    console.log('replying to:', pkt.body.id_reply)
    hub.send( pkt.body.id_reply, { ts: new Date, echo: pkt.body })
Send a message and await a reply
const reply = hub.local.addReply()
  { msg: 'hello readme example with reply',

reply.then( ans => {
  console.log('Received reply', ans) 

Connections and Platforms

Browser hub connections

Works out of the box with Web APIs like:


hub.web.connect( a_message_channel.port1 )
hub.web.connect( a_web_worker || self )
hub.web.connect( an_iframe )

hub.web.connectWS( a_websocket )
hub.web.connectStream( an_rtc_data_channel )
NodeJS hub connections

Works out of the box with NodeJS APIs like:

See plugins/net


hub.tcp.connect({ host, port })

hub.tls.createServer( tls_options )
hub.tls.connect({ host, port })

hub.direct_stream.connect( hub_other )

// WebSockets also work server-side
hub.web.connectWS( a_websocket )
Same-process hub connections

See plugins/direct hub_other )


2-Clause BSD

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free