In this video we are going to learn about Piping the Stream.
Piping is a mechanism where we provide the output of one stream as the input to another stream.
It is normally used to get data from one stream and to pass the output of that stream to another stream.
There is no limit on piping operations.
Now we'll show a piping example for reading from one file and writing it to another file.



var fs = require(\"fs\");

var readStream = fs.createReadStream(__dirname + '/message.txt','utf8');
var writeStream = fs.createWriteStream(__dirname + '/message3.txt');
readerStream.pipe(writerStream);
console.log(\"Program Ended\");



Now lets run.
So goto command prompt and run the index.js file.


node index.js


Now lets go to the project and you can see here a new file has been created.
Just open the file and you can see the the content.
So in this way you can Piping the stream in node js.