September 2017
Intermediate to advanced
216 pages
6h 8m
English
Let's start by iterating over a collection and writing each value as a line to an output file:
const myList = Range() .map(v => `Value${v}`) .take(20) .toList();const output = fs.createWriteStream( './output/05-writing-collection-data');output.on('close', () => { console.log('done');});myList.forEach((v) => { output.write((v + os.EOL));});output.end();
The values that we're trying to write to a file are simple strings from myList. The output stream is ready for writing as soon as it's created with fs.createWriteStream(). In the side-effect we've created with forEach(), we're writing each value from the collection to the output stream using the write() method. When the forEach() loop exits, we signal ...
Read now
Unlock full access