Monday, December 12, 2016

Node.js Tutorial for Beginners 11 - Basics of Streams - Readable Stream





var fs = require('fs');

var readStream = fs.createReadStream('file.txt');
readStream.setEncoding('utf8');
var data = '';
readStream.on('data', function(chunk) {
    console.log('------------------------------------------------------------');
    data += chunk;
    //console.log(chunk);
})

readStream.on('end', function(chunk) {
    console.log(data);
    console.log('--------------------End----------------------------------------');
})