What are streams in Node.js, and why are they useful?

Streams are objects that allow reading and writing data in a continuous flow, making them efficient for processing large amounts of data. There are four types of streams: Readable, Writable, Duplex, and Transform. For example, using a readable stream to read a file:

const fs = require('fs');
const readableStream = fs.createReadStream('largeFile.txt');

readableStream.on('data', chunk => {
  console.log(`Received ${chunk.length} bytes of data.`);
});

readableStream.on('end', () => {
  console.log('No more data.');
});