DEV Community

Anjali Gurjar
Anjali Gurjar

Posted on

Read stream Write Stream Work together use(Pipe)

const fs = require('fs');
const readStream = fs.createReadStream('input.txt');
const writeStream = fs.createWriteStream('output.txt');

// Pipe the readable stream to the writable stream
readStream.pipe(writeStream);

// You can also handle events for more control
readStream.on('data', chunk => {
console.log(Reading chunk: ${chunk.length} bytes);
});

writeStream.on('finish', () => {
console.log('Write operation finished!');
});

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more