I'm using superagent
to receive a notifications stream from a server
require('superagent')
.post('www.streaming.example.com')
.type('application/json')
.send({ foo: 'bar' })
.on('data', function(chunk) {
console.log('chunk:' + chunk); // nothing shows up
})
.on('readable', function() {
console.log('new data in!'); // nothing shows up
})
.pipe(process.stdout); // data is on the screen
For some reason data
and readable
events aren't registered, hovewer I can pipe data to the sceeen. How can I process data on the fly?
Looking at the source of
pipe
method, you can get access to the originalreq
object and add listeners on it:But this won't handle the redirection if any.
It looks like
superagent
doesn't return a real stream, but you can use something likethrough
to process the data:(although you have to check if
superagent
won't first download the entire response before it sends data through the pipe)