Streams: Streams are a way to handle data in Node.js. They allow you to read and write data in chunks, which can be more efficient than reading or writing the entire file at once. Here's an example of how to use streams to read a file:
javascript
const fs = require('fs');
const stream = fs.createReadStream('/path/to/file');
stream.on('data', (chunk) => {
console.log(chunk);
});
stream.on('end', () => {
console.log('Finished reading file');
});
No comments:
Post a Comment