duplex-json-stream

    1.0.1 • Public • Published

    duplex-json-stream

    Turn a transport stream into an duplex stream that parses from / serializes to json

    npm install duplex-json-stream
    

    build status

    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

    Keywords

    none

    Install

    npm i duplex-json-stream

    DownloadsWeekly Downloads

    14

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • mafintosh