9951 explained code solutions for 126 technologies

nodejsHow to pipe streams

You might want to use pipeline() as a better alternative that will properly clean memory after stream processing.

const fs = require('fs');
let input = fs.createReadStream('/var/www/examples/test.txt');
let output = fs.createWriteStream('/tmp/out.txt');
input.pipe(output);ctrl + c

library to work with file system


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


open file and create writing stream from it


path to file to stream read


path to file to write stream to


pipe input stream to output (in our case - read from input file and write to output)