npm install duplex-emitterTurns a duplex streams into an event emitter.
``javascript
var s = net.connect(...);
var duplexEmitter = require('duplex-emitter');
var emitter = duplexEmitter(s);
`
You can emit events. They will be serialized (to JSON) and piped to the stream.
`javascript`
emitter.emit('event1', arg1, arg2); // Send event to the other side
You can listen for events from the peer:
`javascript``
// Got event from the peer
emitter.on('event2', function(arg1, arg2), {
//...
})