9951 explained code solutions for 126 technologies


nodejsHow to read stream to Buffer


const fs = require('fs');
let input = fs.createReadStream('/var/www/examples/test.txt');

input.on('data', buf => {
  console.log(buf);
});ctrl + c
require('fs')

library to work with file system

fs.createReadStream(

create stream to read data from (file in our case)

/var/www/examples/test.txt

path to file to stream read

.on('data'

handle date reading from stream

buf

buffer gets data chunk read from stream