Skip to content

How to Write huge amounts of data using stream in Node.js

Notifications You must be signed in to change notification settings

Mandeepmat/Node.js-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Node.js-stream

How to Write huge amounts of data using stream in Node.js const fs = require('fs');

// Define the file path where you want to write the data const filePath = 'huge_data.txt';

// Create a writable stream const writableStream = fs.createWriteStream(filePath);

// Generate a large amount of data (for demonstration purposes) const data = 'This is a line of data.\n'.repeat(1000000); // Creating 1 million lines of data

// Write the data to the stream writableStream.write(data, 'utf-8', () => { console.log('Data has been written to the file.'); // Once all data is written, close the stream writableStream.end(); });

// Handle stream events writableStream.on('finish', () => { console.log('Write operation is complete.'); });

writableStream.on('error', (err) => { console.error('Error writing data:', err); });

About

How to Write huge amounts of data using stream in Node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published