node.js - Nodejs - Piping MU2 to HTTP? -


mu (node.js mustache engine) documents method of using util.pump() read stream http write stream. util.pump() has been deprecated in favor of pipe() method on stream object.

so test doing is:

var http = require('http'); var mu = require('mu2');  http.createserver(function(req, res) {     mu.compiletext("testname", "hello world");     var stream = mu.render("testname", {});     stream.pipe(res);     res.end(); }).listen(8888); 

but doesn't output anything. tried util.pump() , didn't work either.

i am, however, able attach on-data event mu::render() , write data res way.

what doing wrong when piping the mu stream http?

i'm using node version 0.10.5 , mu2@0.5.17.

the solution check mu steam end event before ending http response stream:

var http = require('http'); var mu = require('mu2');  http.createserver(function(req, res) {     mu.compiletext("testname", "hello world");     var stream = mu.render("testname", {});     stream.pipe(res);      // here's trick.     stream.on('end', function() {         res.end();     }); }).listen(8888); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -