eval-stream

Evaluate streams of JavaScript code in a given context

eval-stream

Evaluate streams of JavaScript code in a given context.

Here, we read the body of an adding function from a simple through-stream:

var PassThrough = require('stream').PassThrough ||
                  require('readable-stream/passthrough');
var assert = require('assert');
 
var evalStream = require('eval-stream');
 
var ts = new PassThrough();
 
ts.pipe(evalStream({
    a: 1,
    b: 2
  }, function (errresult) {
    assert(!err);
    assert.equal(result, 3);
  }));
 
ts.write('return a + b;');
ts.end();