Question from the Node.js test

Write a NodeJS program that reads the file foobar.txt and outputs the lines in reverse order to stdout.

Medium

Consider the filefoobar.txt containing exactly the following data:

foo
baz bar
qux quxx
cork
grault garply
waldo

What will the following code output tostdout? :

const fs = require('fs');
const through = require('through2');

fs
  .createReadStream('foobar.txt')
  .pipe(through(function(data) {
    this.push(data.toString().split('\n').reverse().join('\n'))
  }))
  .pipe(process.stdout);
Author: Jean-marie CléryStatus: PublishedQuestion passed 905 times
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!