How to use fs.createReadStream

Introduction

In this blog post, you will lean how to use fs.createReadStream() method in your Node.js application. The createReadStream() method is an inbuilt API of fs module which allows you to open up a readable stream( file/stream )and read the data present in it.

Syntax

fs.createReadStream( path, options )

This method accept two parameters as described below:

  • path: The path of the readable stream . It could be a string, buffer or URL.
  • options: An optional parameter .

 This method returns the fs.ReadStream object.

Following code snippet illustrates fs.createReadStream() method usage:

const fs = require('fs'),
  
// Use fs.createReadStream() method to read a file
reader = fs.createReadStream('foo.txt');
  
// Read and display the file data on console
reader.on('data', function (chunk) {
    console.log(chunk.toString());
});

// Error handler to catch any errors that happen while creating the readable stream
reader.on('error', function(err) {
    console.log("Error occurred:",err)
  });

#node.js createreadstream pipe #node.js createreadstream async await #node js createreadstream from buffer #node js createreadstream sync #node.js createreadstream encoding #node js createreadstream from url #node js createreadstream close #node js readstream #node js createreadstream #node.js createreadstream async #node js readstream buffer #node js create read stream from buffer #createreadstream nodejs #node.js createreadstream example #node.js readstream event #node js fs createreadstream error handling #node js create read stream from string #node js create read stream from url #node js create read stream from file #node.js fs.createreadstream pipe #node js readstream from buffer #createreadstream in node js #fs.createreadstream nodejs #createreadstream node js example #createwritestream example nodejs #node js readstream pipe #node js readstream size #node.js string to createreadstream #node js readstream example fs.createreadstream is not a function #fs.createreadstream nodejs #fs.createreadstream from buffer #fs.createreadstream from url #fs.createreadstream example #fs.createreadstream is not a function react #fs.createreadstream events #fs.createreadstream in react native #fs.createreadstream async await #fs.createreadstream async #fs.createreadstream alternative #fs.createreadstream angular #fs.createreadstream axios #fs.createreadstream autoclose #fs.createwritestream async #fs.createwritestream append #fs.createreadstream base64 #fs.createreadstream buffer #fs.createreadstream binary #fs.createreadstream blob #fs.createreadstream buffer size #fs.createreadstream browser #fs.createwritestream buffer #fs.createwritestream buffer example #fs.createreadstream csv #fs.createreadstream close #fs.createreadstream catch error #fs.createreadstream chunk size #fs.createreadstream callback #fs.createreadstream chunk #fs.createreadstream cypress #fs createwritestream create directory #fs.createreadstream documentation #fs.createreadstream directory #fs createreadstream dest on is not a function #fs.createreadstream download #fs createwritestream directory #fs.createreadstream on data #fs.createreadstream return data #fs.createreadstream error handling #fs.createreadstream encoding #fs.createreadstream end #fs.createreadstream enoent #fs.createreadstream error write after end #fs-extra createreadstream #fs.createreadstream from base64 #fs.createreadstream from string #fs.createreadstream from blob #fs.createreadstream from file #fs.createreadstream file not found #fs.createreadstream formdata #fs.createreadstream( #fs.createreadstream get length #fs.createreadstream get string #fs.createreadstream highwatermark #fs.createreadstream http #fs.createwritestream highwatermark #fs readstream highwatermark #fs.createreadstream in node js #fs.createreadstream in react #fs.createreadstream is not a function vue #fs.createreadstream is not a function cypress #fs.createreadstream image #fs.createreadstream javascript #fs.createreadstream json #fs.createwritestream json #fs.createwritestream javascript #js fs.createreadstream #node.js fs.createreadstream pipe #fs.createreadstream node js #fs.createreadstream line by line #fs.createreadstream local file #fs readstream line by line #fs.createreadstream memory leak #fs.createreadstream multiple files #fs.createreadstream memory #fs.createreadstream method #fs.createwritestream mode #mock fs.createreadstream #fs.createreadstream not working #fs.createreadstream node #fs.createreadstream not a function #fs.createwritestream nodejs #fs.createwritestream not working #fs.createwritestream new line #fs.createwritestream new file #fs.createreadstream on end #fs.createreadstream on #fs.createreadstream on error #fs.createreadstream options #fs.createreadstream output #fs.createreadstream on finish #fs.createwritestream options #fs.createreadstream pipe #fs.createreadstream promise #fs.createreadstream path #fs.createreadstream pipe csv #fs createreadstream pipe promise #fs.createreadstream pause #fs.createreadstream pdf

, , ,

Related posts

Latest posts

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Please disable your adblocker or whitelist this site!

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site