Node JS Tutorial for Beginners #14 - Readable Streams

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ก.พ. 2025

ความคิดเห็น • 149

  • @broken_arrow1813
    @broken_arrow1813 6 ปีที่แล้ว +21

    This is one of the few channels that you realize from the onset that the instructor understands what he is talking about and knows how to share the knowledge. Thank you sir!

  • @nhatminhchannhan
    @nhatminhchannhan 7 ปีที่แล้ว

    i am a mobile dev, the first time i come with NodeJS, i saw many tut on the internet, but this series video is the best fot beginer :D, many thanks ^^

  • @carmensandoval5581
    @carmensandoval5581 3 ปีที่แล้ว +1

    Thanks for sharing your knowledge! I'm pretty new to node.js, and I had trouble reading data received from an API call because it was in chunks (). Thanks for explaining that it all comes down to specifying the 'character encoding' and making everything seem so easy and simple.

  • @cocosisiyaya
    @cocosisiyaya 3 ปีที่แล้ว

    I have hard time to understand the Stream, after watch ur video, I just got it so easily. Thank you so much ! you are awesome!!!

  • @deepdivedevs100
    @deepdivedevs100 4 ปีที่แล้ว +13

    It is a crime to dislike these videos 😂😂

  • @asiabork5441
    @asiabork5441 8 ปีที่แล้ว +33

    You are an amazing teacher! Thank you ;)

  • @jora5483
    @jora5483 4 ปีที่แล้ว +1

    Fantastic tutorial... buffer and streams are simply and clearly explained

  • @michelepaglialonga9382
    @michelepaglialonga9382 7 ปีที่แล้ว +3

    for me... the best nodejs tutorial i found!

  • @ovidiu-constantinhriscu9640
    @ovidiu-constantinhriscu9640 6 ปีที่แล้ว +1

    High quality tutorials, you've earned yourself a subscriber

    • @NetNinja
      @NetNinja  6 ปีที่แล้ว +1

      Thanks :)

  • @arbazkhan-od9sk
    @arbazkhan-od9sk 6 ปีที่แล้ว

    this indeed is the best tutorials in the world

  • @soultouchingsongs
    @soultouchingsongs 7 ปีที่แล้ว +4

    Excellent. You are one of the best teacher. Thank you!

    • @NetNinja
      @NetNinja  7 ปีที่แล้ว

      Thanks!

    • @nabeeltech7885
      @nabeeltech7885 6 ปีที่แล้ว

      i am gonna pass my web development semester through ur tutorials

  • @mrNobody5638
    @mrNobody5638 8 ปีที่แล้ว +18

    For those of you who wonder why the buffer is not presenting as the file text after adding utf8 as 3rd parameter:
    pass an object as 3rd parameter {encoding: 'utf8'} like this:
    var myReadStream = fs.createReadStream(__dirname + '/readme.txt', {encoding: 'utf8'});

    • @nicot2895
      @nicot2895 6 ปีที่แล้ว +9

      Just a note. Actually, you don't need to do that. I will explain you why:
      First, the dirname + readMe thing is only one parameter, which makes utf8 the second one.
      Note: You also want to write readMe with capital M, unless you named the file differently.
      Taking that into account, the docs of Node say about the options object: "If options is a string, then it specifies the encoding." Now I just learned about this and it's cool. Means if you just say 'utf8' (notice quotation, because it's a string), then you don't need the options object at all. Cool! :)

  • @graphicredesign1492
    @graphicredesign1492 6 ปีที่แล้ว +1

    Great tutorial. I'm going through them all sequentially. For this tutorial, a brief explanation as to what these number values in the buffer represent would be nice. I assume that they correspond with the text in some way, but the tutorial did not go into this in order to confirm.

  • @omerdoron1110
    @omerdoron1110 6 ปีที่แล้ว +1

    Great tutorial. You are a great teacher!

  • @rachitkanaujia007
    @rachitkanaujia007 5 ปีที่แล้ว

    bestest of the best node.js tutorial. Thanks a lot.

    • @NetNinja
      @NetNinja  5 ปีที่แล้ว

      Thanks dude 😊

  • @edwardanthony7134
    @edwardanthony7134 5 ปีที่แล้ว +4

    Just a small correction, __dirname is not a global property. Every node js file is actually wrapped in function when it's executed. And one of the parameters is __dirname.
    Below you could see the wrapper function:
    function (exports, require, module, __filename, __dirname) {
    // file contents here.
    }
    That's the reason __dirname and __filename is unique to each file, if it's listed under the global object, it won't be unique.

    • @_samirdahal
      @_samirdahal 5 ปีที่แล้ว

      that should be a IIFE function BTW

  • @muhammadnabeelasif1235
    @muhammadnabeelasif1235 2 ปีที่แล้ว

    That's some valuable content. Thank you :)

  • @MW-Code
    @MW-Code 8 ปีที่แล้ว +4

    just wow - more please ! xD

  • @Dosomecode
    @Dosomecode 7 ปีที่แล้ว +2

    thanks, sir.. finally I understand node js

  • @chardos
    @chardos 7 ปีที่แล้ว

    Awesome videos mate, thanks for making these!

  • @franckapik
    @franckapik 8 ปีที่แล้ว +1

    Thank you a lot !!! You are a really good teacher !!! It help me a lot !

  • @Sober_Travel
    @Sober_Travel 2 ปีที่แล้ว

    Thanks! so easy video. Make more node videos

  • @DaveVoyles
    @DaveVoyles 8 ปีที่แล้ว +1

    Fantastic overview.

  • @The0posthuma
    @The0posthuma 5 ปีที่แล้ว +2

    you can pipe the output of this file to and then search for the chunks:
    node server.js | less
    then you search with /new

    • @mhdunknown
      @mhdunknown ปีที่แล้ว

      also, while in `less` after searching for a specific string, you can press `n` for the next results, and press `shift+n` for the previous results.

  • @sudheerpoojary8975
    @sudheerpoojary8975 3 ปีที่แล้ว

    very best tutorial

  • @yashpreetbathla4653
    @yashpreetbathla4653 4 ปีที่แล้ว

    Thank you so much :) you teach really nice!

  • @SilentDrifts
    @SilentDrifts 4 ปีที่แล้ว

    I would like to thank you for the effort you made it do this tutorial. by the way, can we use this function for reading an image buffer?

  • @gokusaiyan1128
    @gokusaiyan1128 7 ปีที่แล้ว +4

    How buffer size / chunk size is decided ?? how does it decide that it will need 2 chunks ?

    • @mhdunknown
      @mhdunknown ปีที่แล้ว +1

      the default is 64KB (65,536 bytes), you can set it to whatever you want by passing a config options object and setting the highWaterMark property like this to 900KB for example:
      const readableStream = fs.createReadStream(__dirname + "/loremIpsum.txt", { highWaterMark: 900000 });
      You can check the buffer's size with:
      console.log(readableStream.readableHighWaterMark); // outputs 65536 bytes, the default buffer size, assuming you didn't change highWaterMark.

  • @nawabali385
    @nawabali385 4 ปีที่แล้ว

    Sir I am in love with your teaching skills as well as coding skills. Can I talk to you please if there is a way? Please Sir ;)

    • @NetNinja
      @NetNinja  4 ปีที่แล้ว

      Hey you can message me on Instagram @thenetninja :) . I'll try my best to reply but cannot always do so.

  • @csaa7659
    @csaa7659 8 ปีที่แล้ว

    great video, thank you

  • @manosriram
    @manosriram 6 ปีที่แล้ว +1

    you can set encoding by using the built in function tooo..like :
    myReadStream.setEncoding('utf-8');

    • @azahid1aza751
      @azahid1aza751 5 ปีที่แล้ว +1

      Doing , 'utf8' as an argument takes up less characters and less time.

  • @_mansoor
    @_mansoor 8 ปีที่แล้ว

    awesome...!!! i am subscribed to you wagan...

  • @spicychile
    @spicychile 6 ปีที่แล้ว +49

    Why am I amused by the way you say 'chunks'.

    • @adityajain019
      @adityajain019 4 ปีที่แล้ว

      scottish??

    • @nickwoodward819
      @nickwoodward819 3 ปีที่แล้ว

      @@adityajain019 Basically, although I think he'd have something to say about that XD

  • @zeroxcub
    @zeroxcub 8 ปีที่แล้ว

    Great video, thanks, I'd like to know what extension you use to have terminal into atom

  • @ThiefKingBakuraX
    @ThiefKingBakuraX 8 ปีที่แล้ว

    Great keep it up!

  • @madzbenito878
    @madzbenito878 4 ปีที่แล้ว +1

    Great tutorial, I used arrow function and it translated the content of my lorem ipsum. I didn't include utf-8
    readableStream.on('data', (chunk) => console.log("New Chunk Recieved " + chunk))

    • @aldrinjenson
      @aldrinjenson 4 ปีที่แล้ว

      You must have included them in the createReadStream function right?

    • @feliksbekeshov7668
      @feliksbekeshov7668 4 ปีที่แล้ว

      why his tutorial doesnt work and we should think and change some things?

    • @madzbenito878
      @madzbenito878 4 ปีที่แล้ว

      Feliks Bekeshov Net ninja posted updated NodeJS tutorials bro. Some of this lessons are outdated

  • @lcrespilho
    @lcrespilho 8 ปีที่แล้ว +1

    In Portuguese we say: "Caralho, que aula foda. Puta que pariu!"
    Translating: "Good teacher." =)

    • @dudeguy8864
      @dudeguy8864 5 ปีที่แล้ว

      LMAO, I put into google translate!

  • @vijaymishra4232
    @vijaymishra4232 7 ปีที่แล้ว

    very nice .. thank you :)

  • @JarosawRewers
    @JarosawRewers 8 ปีที่แล้ว

    great, thank you!

  • @YousefSh
    @YousefSh 2 ปีที่แล้ว

    Can I create a read stream from a file on the internet? Also... it was difficult to find documentation on this. Thank you for this video!

    • @Uthael_Kileanea
      @Uthael_Kileanea 2 ปีที่แล้ว

      I'd assume you provide a link to the file instead of a path to your directory.

  • @EscuadraAlbiazul
    @EscuadraAlbiazul 8 ปีที่แล้ว

    You're the best.

  • @adityachopra3759
    @adityachopra3759 5 ปีที่แล้ว

    Is this tutorial series sufficient as a pre-requisite for other courses which make use of node js development like in chatbots?

  • @yohangarcia01
    @yohangarcia01 4 ปีที่แล้ว

    THANK YOU

  • @winningzhang2158
    @winningzhang2158 7 ปีที่แล้ว +1

    I am good at English, but I can see it ,thanks a lot

  • @VAnishRao
    @VAnishRao 8 ปีที่แล้ว

    Thanks for the brilliant tutorial..
    So .. Can I define my own chunk size to read? I can see that the chunk size is quite high..

  • @stevei6911
    @stevei6911 7 ปีที่แล้ว

    wonderful

  • @melsaied101
    @melsaied101 3 ปีที่แล้ว

    Thank you

  • @adriatic123
    @adriatic123 7 ปีที่แล้ว +5

    Excellent tutorial, thanks. Just one small correction (as of Oct 2017), in fs.createReadStream() instead of 'utf8' parameter, it should be {encoding: 'utf8'}
    Thanks

    • @nicot2895
      @nicot2895 6 ปีที่แล้ว +5

      Just a note. Actually, you don't need to do that.
      I will explain you why:
      The docs of Node say about the options object: "If options is a string, then it specifies the encoding." (nodejs.org/api/fs.html#fs_fs_createreadstream_path_options) Now I just learned about this and it's cool. Means if you just say 'utf8' (notice quotation, because it's a string), then you don't need the options object at all. Cool! :)

  • @TheGuroguro12
    @TheGuroguro12 7 ปีที่แล้ว

    Thank you very much......

  • @albertpatterson8164
    @albertpatterson8164 7 ปีที่แล้ว

    I like this.

  • @shaharglatman2441
    @shaharglatman2441 4 ปีที่แล้ว

    what makes the reading emitted? is it the createReadStream? in this case aren't we losing the first chunks that come before we used "on" to listen ? i feel like we need to listen first and then start the reading. what am i missing?

    • @mhdunknown
      @mhdunknown ปีที่แล้ว

      I was curious about this so I asked chatgpt and it explained it nicely. Basically the streaming won't start until the entire module/file is executed. So it's guaranteed that you won't lose any buffer/bytes at all.
      In Node.js when you call `fs.createReadStream()`, it sets up the stream, but the streaming of data (i.e., the reading of data from the file and emitting it as `data` events) does not start immediately at the moment of this call. Instead, the streaming process begins later, allowing you to set up your event listeners in the meantime.
      # Understanding the Flow
      1. Creating the Stream: `fs.createReadStream()` creates a readable stream but doesn't immediately start reading data from the file. It just initializes the stream and gets it ready to read data.
      2. Event Loop Integration: The actual reading of data is integrated with the Node.js event loop. The stream starts reading data when it gets an opportunity to execute within the event loop. This typically happens after the current executing script i.e. the current module/file (including all synchronous code and immediate function calls) completes.
      3. Attaching Event Listeners: This delay before streaming starts allows you to attach event listeners like `readableStream.on('data', callback)`. If the stream started emitting data immediately upon creation, there would be a risk of missing early `data` events before the listeners are set up.
      4. Starting the Stream: The stream effectively starts when Node.js's event loop processes it, which happens after the current tick of the event loop. This behavior ensures that you can attach `data`, `error`, `end`, and other event listeners in the same tick of the event loop as the stream creation, without missing any events.
      # Example
      const readableStream = fs.createReadStream(__dirname + "/readme.txt");
      // Even though the stream is created, it hasn't started emitting 'data' events yet.
      readableStream.on('data', function (block) {
      console.log("new blocks received:");
      console.log(block);
      });
      // The 'data' events will start after this point, when the Node.js event loop begins processing the stream.
      In this example, the `data` event listener is attached immediately after creating the stream, ensuring that you won't miss any of the `data` events once the stream starts emitting them.

  • @nick_jacob
    @nick_jacob 4 ปีที่แล้ว

    If I finish this course and understand it, am I able to get a job working with Node.js or is there a lot more to it than this?

    • @pozeraczstivow6348
      @pozeraczstivow6348 4 ปีที่แล้ว

      a lot more you need to practice

    • @nick_jacob
      @nick_jacob 4 ปีที่แล้ว

      @@pozeraczstivow6348 I pretty much gave up on node.js for right now. I'm coming from JavaScript/PHP/MySQL background and I think I prefer PHP after learning Node.

    • @pozeraczstivow6348
      @pozeraczstivow6348 4 ปีที่แล้ว

      @@nick_jacob NO NO NO IDK IM DRUNK IM VRFRONTEDND I LOVE JAVASCIPRT ANAD IM BASIC REACT IDK LIFE SIS DAD

  • @gokusaiyan1128
    @gokusaiyan1128 7 ปีที่แล้ว +3

    You can also get text by this .
    myReadStream.on('data', function(chunk){
    console.log('new chunk recieved: ' + chunk);
    });

    • @ViewFromAndromeda
      @ViewFromAndromeda 5 ปีที่แล้ว

      Thanks for the tip. I used template string for mine:
      myReadStream.on('data', function(chunk){
      console.log(`New chunk received: ${chunk}`)
      })

  • @chaoschao9432
    @chaoschao9432 7 ปีที่แล้ว +3

    why this is "on" event, not an "emit" event to trigger it happen??

    • @harishpillarisetti6658
      @harishpillarisetti6658 7 ปีที่แล้ว +2

      I guess "emit" is used to fire "user-defined" events, whereas "data" is already defined.

    • @Redmile2006
      @Redmile2006 5 ปีที่แล้ว

      It's because the event is most likely emitted somewhere inside the 'fs' module or some other core module.

    • @SaatvikGuruprasad
      @SaatvikGuruprasad 4 ปีที่แล้ว

      @@harishpillarisetti6658 correct

  • @ronokdev
    @ronokdev 8 ปีที่แล้ว

    awesome

  • @asadbilal591
    @asadbilal591 7 ปีที่แล้ว +1

    Can anyone please tell me why he didnt use
    my ReadStream.emit(data , chunk); ???
    becuase in 8th tutorial he kinda use all three
    the event emitter,the binder (.on) and the .emit.

  • @honeyjar1000
    @honeyjar1000 5 ปีที่แล้ว

    can we send a request from another file? ive tried to do this and it tells me the "require" function is undefined, do i have to tell my files to use node-js somehow?? thank you for the videos!!

  • @onurshenol
    @onurshenol 7 ปีที่แล้ว +2

    how can we determine the size of a chunk ?

    • @AshwinChandarR
      @AshwinChandarR 7 ปีที่แล้ว +1

      Using higherwatermark option after the path in the readstream

  • @user-vq8jv4sz1i
    @user-vq8jv4sz1i 4 ปีที่แล้ว

    Do you or can you do one similar to this but with csv with large file size? Something like 32,000KB? I'm having issues with these chunks and it appears the stream just stops.

  • @quotationscanvas
    @quotationscanvas ปีที่แล้ว

    i have audio file chunks coming in server and i want to play audio from that chunks on the client but unable to do please can you tell me how can i.

  • @scottregb
    @scottregb 6 ปีที่แล้ว

    Is there a way to stream multiple files in a directory into a single file by this method?

  • @mcanonymous-d6h
    @mcanonymous-d6h 3 ปีที่แล้ว

    What is emitting the data event to myReadStream?

  • @ViewFromAndromeda
    @ViewFromAndromeda 5 ปีที่แล้ว

    I only received one chunk as against NetNinja's two chunks. Is it because I'm using a more recent Node.js version?

  • @n_fan329
    @n_fan329 6 ปีที่แล้ว

    One question boss, since we are in the folder what happened if we use only the file name without __dirname ?

  • @kirillpavlovskii8342
    @kirillpavlovskii8342 3 ปีที่แล้ว

    thanks

  • @iqbalibrahim4713
    @iqbalibrahim4713 6 ปีที่แล้ว

    May I know how the event was executed without emitting it, don't we need to emit it like the emitter?

    • @mhdunknown
      @mhdunknown ปีที่แล้ว

      fs.createReadStream() function's implementation internally emits the data.

  • @LinhNguyen-py2ws
    @LinhNguyen-py2ws 7 ปีที่แล้ว +1

    We can use ON & EMIT even we did not use events.Emitter, so why we have eventsEmitter, plesase help me to understand it

    • @SispeharOfficial
      @SispeharOfficial 7 ปีที่แล้ว +2

      It's because 'fs' module inherits emit - meaning that it includes it without specifying seperately.

    • @LinhNguyen-py2ws
      @LinhNguyen-py2ws 7 ปีที่แล้ว

      thank you bro ^^ i got it

  • @DeusGladiorum
    @DeusGladiorum 7 ปีที่แล้ว

    This is an old video but I'm hoping someone may be able to answer this: When exactly does an event listener stop listening? For example what if the data event we're listening for in the tutorial never fires? When I arbitrarily cause it to never fire in my code, the program exits out very quickly, which confuses me because if the whole point of event listeners is to listen out for events, shouldn't it just listen indefinitely, similar to how running listen() on an http.Server object causes your program to remain open indefinitely?

    • @proumkroum4481
      @proumkroum4481 6 ปีที่แล้ว

      This is an old video, you said it. You won't find answers here. Go to reddit or something.

  • @jayashree4130
    @jayashree4130 5 ปีที่แล้ว

    can you explain reading json file, where i manipulate some data then it will write that manipulated data. Because it is storing chucks of data i could not modify my json data. i have 54940 records while readStream it is storing 643 records in first chunk, where the last record is not complete json(example-->{ "_id" : "PERFSTG26226", "bonuses" : [ ) where my json data is incomplete. how can i read exactly if it is storing size wise not according to number of records.

  • @wfhan
    @wfhan 8 ปีที่แล้ว

    i am new to node.js and want to ask, why need to require http as first line of code 'cos in this example, i am not seeing it being use. is there depecencies over at the fs ?

    • @lenardpratt7833
      @lenardpratt7833 8 ปีที่แล้ว +3

      Mike Wong There is no need it just their as a place holder

  • @prathameshkulkarni465
    @prathameshkulkarni465 7 ปีที่แล้ว +1

    Why would you use streams if you can just read files using the fs module?

    • @mohsinshaikh8944
      @mohsinshaikh8944 7 ปีที่แล้ว

      PJ Collazo .

    • @Uthael_Kileanea
      @Uthael_Kileanea 2 ปีที่แล้ว

      He explained it near the end of the video. It's so the user can start reading the data before it's fully read.
      Useful when they want to read a really big file (like a video) or they're on a really slow connection.

  • @abdulkabir7527
    @abdulkabir7527 4 ปีที่แล้ว

    How did he use on function without calling the module above?
    And how is that on function running without using emit.
    I am confused.

    • @shakyamohanty5798
      @shakyamohanty5798 3 ปีที่แล้ว

      because readStream inherits from EventEmitter class where "data" is an event.

    • @Uthael_Kileanea
      @Uthael_Kileanea 2 ปีที่แล้ว

      He DID call the module above.
      myReadStream is actually *fs*.something
      myReadStream.on() would in this case be the same as fs.something.on()

  • @Mraei0u
    @Mraei0u 5 ปีที่แล้ว

    By chunks we mean packages, right?

  • @ahhablahdoo5036
    @ahhablahdoo5036 5 ปีที่แล้ว

    I want to get data about songs currently playing from a radio station. Like getting data from a streaming URL that looks like s2.randomname.com:7392. How do I do this?

  • @anthonyw1476
    @anthonyw1476 7 ปีที่แล้ว

    love it

  • @Pacha_manusyan
    @Pacha_manusyan 6 ปีที่แล้ว

    is there any functions for read pdf file insted of txt file...???

  • @SaiPavanPothuri
    @SaiPavanPothuri 7 ปีที่แล้ว

    why does Node.js force us to stream data rather than buffer it ?
    what are the difference b/w these two ?
    why performance is good in streams as compared to buffer ?

    • @Redmile2006
      @Redmile2006 5 ปีที่แล้ว

      A stream is just packets of data being sent across the connection. So if you are sending some text from the server to the client like:
      The quick brown fox jumps over the lazy dog
      And your buffer is 1 byte, then you will just send one character at a time. If it is 5 bytes, you will send:
      "The q"
      "uick "
      "brown"
      " fox "
      "jumps"
      " over"
      " the "
      "lazy "
      "dog"
      Try to think of each chunk as a box of data, and think of all the data boxes received so far as the buffer. The stream is just the process of transferring of the boxes sequentially from the client to the server. So as soon as the client program receives the first chunk, it can display The q, then The quick , then The quick brown, etc, etc. The buffers ARE the stream. But normally a program, like a web browser, will wait until all the data is received to display the web page (imagine what the page would look like if only half the code is there). But if you are sending audio or video, the browser will start displaying whatever it has received so far once there is enough data in the buffer. The process is essentially the same whether you are sending text data or video data, because all the data is sent as bytes. It is up to the client to interpret them. When you stream a video online and it says "buffering", it means your browser is processing and playing the video/audio data quicker than it is being downloaded, so you got to the last chunk and now you have to wait for a bunch of new packets to come in from the server (ie, it's loading new data into a buffer that you can start reading from again). You have 'consumed' all the data in all the boxes you have received, and it won't start streaming again until it receives a certain amount of data to give you a good new buffer.
      If you think about it, all data transfer from a server to a client is a stream, and all the data received so far on the client-side is the buffer. Even if you sent a stream of characters one at a time, as soon as you receive 1 character, you are filling your buffer, even if you consume it immediately. The buffer is just some temporary space in memory to store the data you've received. Then the data can be displayed to you, or saved to the disk, cached, etc.

  • @heartout9757
    @heartout9757 5 ปีที่แล้ว

    why aren't we considering public while giving path since __dirname adds only node-js-playlist

  • @octoberfest7273
    @octoberfest7273 3 ปีที่แล้ว

    HI. I have a question. How we can see how works buffer with chunks without FileSystem module, but only with stream module
    For example
    const { Readable } = require('stream');
    class Ever extends Readable {
    constructor(opt) {
    super(opt)
    }
    _read(chunks) {
    ....
    }
    let myRead = new Ever({});
    myRead.on('data', (chunks) => {
    console.log('Received: ');
    console.log(chunks);
    });

  • @Xanchs4593
    @Xanchs4593 5 ปีที่แล้ว

    Hey my question is if I wanted to wait lets say 2 seconds after every chunk read, how would I do that?

    • @aldrinjenson
      @aldrinjenson 4 ปีที่แล้ว

      Hey, did u find an answer for this?

    • @Xanchs4593
      @Xanchs4593 4 ปีที่แล้ว

      @@aldrinjenson stackoverflow.com/questions/59467912/wait-after-every-read-of-a-chunk-of-data-node-js

  • @AmanChawlaBIT
    @AmanChawlaBIT 4 ปีที่แล้ว

    why to specify directory name here,, can't we read a file using readstream by writing the file name only??

  • @kaspo1810
    @kaspo1810 4 ปีที่แล้ว

    Can anyone help... If I want to bold the text in console.log('Hey there'); then what should I use?

  • @rosjio99
    @rosjio99 7 ปีที่แล้ว

    If you want to read a .json file could you use .createReadStream or should you use readFile/Sync? What's the real difference between the two?

  • @surajoberai
    @surajoberai 5 ปีที่แล้ว

    do we really need to include "var http = require('http');" in code,my code just worked fine.let me know if i m missing something. thanks in advance

  • @FredoCorleone
    @FredoCorleone 6 ปีที่แล้ว

    How do I create a read stream with buffer of exactly one line?

  • @geekybot
    @geekybot 3 ปีที่แล้ว

    // guys ignore this
    const http = require('http');
    const fs = require('fs');
    // createReadStream inherits from events.EventEmitter
    let myReadStream = fs.createReadStream(__dirname + '/readMe.txt' , 'utf8'); // if utf8 is not mentioned bytes will be returned
    // Every time when a stream is ready it emits an event names data
    myReadStream.on('data', function(chunk){ // listening for 'data'
    console.log('new chunk: ' );
    console.log(chunk);
    }

  • @keremylmaz9595
    @keremylmaz9595 6 ปีที่แล้ว

    Nice :D

  • @psrs985
    @psrs985 7 หลายเดือนก่อน

    what is the size of each chunk

    • @himxai
      @himxai 7 หลายเดือนก่อน +1

      the heightest water marker is probaliy 1024 or 1kb

  • @Akeeets
    @Akeeets 5 ปีที่แล้ว

    How is the myReadStream data event emitted?

    • @azahid1aza751
      @azahid1aza751 5 ปีที่แล้ว

      View this link for more information nodejs.org/api/all.html#fs_fs_createreadstream_path_options

  • @tanmayanand9976
    @tanmayanand9976 6 ปีที่แล้ว

    When I concatenate the chunk with “new data received:” it logs the whole text. Can you give a explanation?

    • @tonym_123
      @tonym_123 5 ปีที่แล้ว

      Because it cast it to String type

  • @Mythanuja
    @Mythanuja 8 ปีที่แล้ว

    Great
    Why you do not emit this data event

    • @Redmile2006
      @Redmile2006 5 ปีที่แล้ว

      How would you know when to emit it? You wouldn't, because it's a builtin functionality. You can emit your own events like in the previous tutorials, but node can also emit events, which you can make your script listen for, just like you can listen for events in a browser in javascript (ie. onload, onclick, etc.). Think of this as ondata

  • @mohanishsaim9537
    @mohanishsaim9537 3 ปีที่แล้ว

    why he not imported events module ???

  • @eswaraprasad345
    @eswaraprasad345 7 ปีที่แล้ว

    how to remove particular line from file ?
    file.text
    1 abc def
    2 abc def
    3 abc def
    4 abc def
    after deleting(3rd line removed)
    1 abc def
    2 abc def
    4 abc def

  • @darylebinum
    @darylebinum 4 ปีที่แล้ว

    I tried concatenating [ console.log(chunk, + 'New chunk recieved:'); ] and got the text then a NaN value. Then i tried [ console.log('New chunk recieved:', + chunk); ] and got New chunk recieved: NaN
    New chunk recieved: NaN. Why does this happen? I know NaN means Not A Number.

    • @darylebinum
      @darylebinum 4 ปีที่แล้ว

      Also when I used Chalk to change the colour of the output I didnt need to insert 'utf8' it automatically changes the encoding to 'utf8' for you.

  • @cityrunner-x3x
    @cityrunner-x3x 2 ปีที่แล้ว

    What are those inside buffer bracket is called. 4c 6f 72 65 blah blah blah.

  • @wazzadev7209
    @wazzadev7209 5 ปีที่แล้ว

    Only getting one chunk

  • @ceasardg
    @ceasardg 2 ปีที่แล้ว

    can anyone tell me what is the accent

  • @Uthael_Kileanea
    @Uthael_Kileanea 2 ปีที่แล้ว

    I only get one "new chunk received:" and under it is the whole text. Without the 'utf8', it says:
    My Lorem_Ipsum.txt is 53kB. Why does it read it all at once? How do I split it into more than one chunk?

    • @Uthael_Kileanea
      @Uthael_Kileanea 2 ปีที่แล้ว

      For anyone else wondering about this, I've found the answer. Visual Studio Code says: "Unlike the 16 kb default highWaterMark for a stream.Readable, the stream returned by this method has a default highWaterMark of 64 kb."
      So I copy-pasted the whole file's contents so it's 106kB and now it makes 2 chunks :)
      One step closer to understanding it all.

  • @keivansf3459
    @keivansf3459 2 ปีที่แล้ว

    thanks