In this video we are going to learn about readable stream.
Streams are one of the fundamental concepts that power Node.js applications.
Streams are a way to handle reading/writing files, network communications or any kind of end-to-end information exchange in an efficient way.
Instead of a program reading a file into memory all at once like in the traditional way, streams read chunks of data piece by piece, processing its content without keeping it all in memory.
This makes streams really powerful when working with large amounts of data.
There are 4 types of streams in Node.js:
Writable: streams to which we can write data.
Readable: streams from which data can be read.
Duplex: streams that are both Readable and Writable.
Transform: streams that can modify or transform the data as it is written and read.
Lets see the readable stream.
So goto the project and inside the index.js file.
First of all require the http and fs package.


var http = require('http');
var fs = require('fs');


Now create a text file inside the project.
So just click on new file.
let say file name is message.txt.
Now add some paragraph here.
So for that go to the https://loremipsum.io/.
From here just generate 30 paragraph and just copy and paste inside the message.tx file.

Now inside the index.js file create read stream.


var readStream = fs.createReadStream(__dirname + 'message.txt');
readStream.on('data',function(chunk){
    console.log('new chunk recieved:');
    console.log(chunk);
});



Now lets run it.
So goto the command prompt and run the command.


node index.js


You can see here the records in chunk.
Now I add here here encoder utf8.
Then it will give the actual text.

var readStream = fs.createReadStream(__dirname + 'message.txt','utf8');
readStream.on('data',function(chunk){
    console.log('new chunk recieved:');
    console.log(chunk);
});


Switch to the command prompt and re-run the index.js file.
You can see the text.
So in this way you can use readable stream.