adds code


📫 Business - jawadrana2015@gmail.com In Node.js, file streams provide a way to efficiently read from or write to large files by processing them in smaller, manageable chunks. This approach minimizes memory usage and improves performance, especially when dealing with files that are too large to fit entirely into memory. Here's an overview of file streams in Node.js using the fs (File System) module: Readable Streams: Readable streams are used for reading data from a source, such as a file. You can create a readable stream using the fs.createReadStream() method. Writable Streams: Writable streams are used for writing data to a destination, such as a file. You can create a writable stream using the fs.createWriteStream() method. let fs = require("fs") let readbleStream = fs.createReadStream("input.txt") let data = "" readbleStream.setEncoding("UTF8") readbleStream.on("data",function(chunk){ ///here we can perform actions on piece of data data +=chunk }) readbleStream.on("end",function(){ console.log(data) }) let writeData = "Hello Word from NODE JS" let writableStream = fs.createWriteStream("output.txt") writableStream.write(writeData,"UTF8") writableStream.end() writableStream.on("finish",function(){ console.log("Write Stream has finished writing...!") }) #nodejs #javascript #coding #node #backend #nodejstutorial #nodejsdevelopment #tutorial #tutorials #programming #nodeprogramming
Previous Post Next Post