Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing util.pump() in Node.js

I recently updated to the latest version of Node.js (1.10~) from 0.8~, and I've been getting a message when running that says:

   util.pump() is deprecated. Use readableStream.pipe() instead.

I've tried to switch my functions to say readableStream.pipe(), but I don't think it's working the same.

So I have three questions:

  1. Why is util.pump deprecated?
  2. How do I switch to readableStream.pipe()? OR 3. How do I turn off this warning?

Here is the code where I'm using it (with mustache)

   var stream = mu.compileAndRender(template_file, json_object_from_db);
       util.pump(stream, res);

When I replace util.pump with readableStream.pipe, I get this error:

ReferenceError: readableStream is not defined

Can anyone help point me in the right direction?

like image 528
streetlight Avatar asked May 05 '13 04:05

streetlight


1 Answers

Okay, so this question was a pretty easy answer after some more experimentation (though documentation was null).

Basically, readableStream is just a variable you're supposed to replace with your stream. So in my case, the answer is:

stream.pipe(res);

You just replace util, basically, with the stream. Easy peezy.

like image 129
streetlight Avatar answered Oct 14 '22 02:10

streetlight