duplex-json-stream
v1.0.1
Published
Turn a transport stream into an object stream that parses from / serializes to json
Downloads
1,386
Readme
duplex-json-stream
Turn a transport stream into an duplex stream that parses from / serializes to json
npm install duplex-json-stream
Usage
var jsonStream = require('duplex-json-stream')
var net = require('net')
var server = net.createServer(function (socket) {
socket = jsonStream(socket) // turn the transport stream into an object stream
socket.on('data', function (data) {
socket.write({echo: data}) // echo back the messages
})
})
server.listen(10000)
var client = jsonStream(net.connect(10000))
client.write({hello: 'world'})
client.on('data', function (data) {
console.log(data) // will print {echo: {hello: 'world'}}
})
License
MIT