dnode is an asynchronous rpc system for node.js that lets you call remote functions.
You can pass callbacks to remote functions, and the remote end can call the functions you passed in with callbacks of its own and so on. It's callbacks all the way down!
var dnode = ;var server =;server;
var dnode = ;var d = dnode;d;
$ node server.js & 27574$ node client.jsbeep => BOOP
.listen() calls in the previous example are just
convenience methods for piping to and from readable/writable streams.
Here's the previous example with the streams set up explicitly:
var dnode = ;var net = ;var server = net;server;
var dnode = ;var net = ;var d = ;d;var c = net;c;
$ node server.js & 27586$ node client.jsbeep => BOOP
Since dnode instances are just readable/writable streams, you can use them with any streaming transport, including in the browser!
First whip up a server:
var http = ;var shoe = ;var ecstatic = __dirname + '/static';var dnode = ;var server = http;server;var sock =;sock;
Then write some browser code:
var domready = ;var shoe = ;var dnode = ;;
Install the dependencies for this example then compile the browser code with browserify:
$ npm install dnode shoe domready ecstatic$ npm install -g browserify$ browserify client.js -o static/bundle.js
Now drop a script tag into static/index.html:
and navigate to http://localhost:9999.
You should see
beep => BOOP on the page!
Check out the complete shoe example.
var dnode =
Create a new readable/writable dnode stream object
All the usual stream methods are at your disposal: pipe(), write(), end().
cons is a function, it will be called
new cons(remote, d) to create a new
instance object. Otherwise its value will be used directly. When
called as a function, the
remote ref will be an empty unpopulated object.
By default, dnode uses weakmaps to garbage collect unused callbacks automatically. This behavior prevents memory leaks in long-running connections.
You can turn weakmaps off by setting
opts.weak = false.
This method is a shortcut for setting up a pipe between
d and a new
The host, port, and callback arguments supplied will be inferred by their types.
If you pass a callback in as an argument, it will be added as a listener to the
Shortcut to create a connection without a constructor.
This method is a shortcut for setting up a
net.createServer() and piping
network streams to and from new dnode streams.
The host, port, and callback parameters will be inferred from the types of the arguments.
Returns a net server object that will also emit
from the underlying dnode streams..
Shortcut to create a listener without a constructor.
This event fires with
cb(remote, d) when the remote side of the connection
has constructed its instance.
This event fires right after the constructed instance has been created locally but before it gets sent to the remote end so you can modify the ref object.
This event fires with
cb(ref, d) where
ref is the local instance object.
This event fires when the remote end causes errors in the protocol layer.
These are non-fatal and can probably be ignored but you could also terminate the connection here.
This event fires when local code causes errors in its callbacks. Not all errors can be caught here since some might be in async functions.
This event fires when the input stream finishes.
With npm do:
npm install dnode
dnode uses a newline-terminated JSON protocol documented in the dnode-protocol project.
These libraries implement the dnode protocol too so you can make RPC calls between scripts written in different languages.