10 Program to demonstrate Readable Stream in NodeJS

Program:

var http = require('http');

var fs = require('fs');



var readStream = fs.createReadStream(__dirname+'/demo.txt');

var chuckCounter = 0;

readStream.on('data',function(d){

    console.log("This is the read data:"+d);

    chuckCounter++;

    console.log('\n\n\n'+chuckCounter);

});



console.log('\n\n\n'+chuckCounter);



Output:

Readable Stream in NodeJS

Previous
Next Post »