Easier interface to dnode.
eNode is a simple wrapper around DNode/upnode functionality, simplifying creation and operation of DNode servers and clients. I like DNode, I just found it used some strange patterns.
- eNode automatically uses upnode's buffering/reconnecting functionality for 'clients'.
- All operations take a callback which fires when ready, but also emit corresponding events.
shutdownfunction will shut down both servers and clients (servers normally require a
end()while a client normally just needs a close().
- All 'connection' handling code is done in the 'connect' event for servers, unlike DNode/upnode where you can set callbacks with the DNode/upnode() function, as well as on 'ready' 'remote' 'connection'.
- Remote API calls get passed the remote/connection properties so they don't necessarily need to be defined inside the scope of connection handler.
- eNode servers automatically keep track of connections and
disconnections, accessible via the server's
// server.jsvar enode = require'enode'var api =callbacknull "server"var server = apilisten5000serveron'connect'console.log'new connection' connectionidremotewhoamiconsole.log'server connected to' valueconsole.log'connected clients' serverconnectionslengthserveron'disconnect'console.log'disconnection' connectionidconsole.log'connected clients' serverconnectionslength
// client.jsvar enode = require'enode'var api =callbacknull "client"var client = apiconnect5000clienton'ready'remotewhoamiconsole.log'client connected to' value