Readable Streams & Fetching large files in Nodejs
Posted on:
Quick post, I was doing a fetch
request in a node script and I wanted to send it directly to a file rather than leave possibly hundreds of megabytes or even gigabytes in memory. Luckily, Node supports streaming, so I just send it to a WriteStream from the built-in fs library which allows me to redirect the chunks as they are streamed down directly into a file.
Reference: MDN - Using Readable Streams