How do I implement a basic node Stream.Readable example?

Viewed 10606

I'm trying to learn streams and am having a little bit of an issue getting it to work right.

For this example, I'd simply like to push a static object to the stream and pipe that to my servers response.

Here's what I have so far, but a lot of it doesn't work. If I could even just get the stream to output to console, I can figure out how to pipe it to my response.

var Readable = require('stream').Readable;

var MyStream = function(options) {
  Readable.call(this);
};

MyStream.prototype._read = function(n) {
  this.push(chunk);
};

var stream = new MyStream({objectMode: true});
s.push({test: true});

request.reply(s);
1 Answers
Related