Exercise: Building a Log Filtering Utility

Create a Node.js utility to filter specific lines from large log files and save the results.

Task

Create a Node.js script that reads a large log file and filters out the lines containing the word "ERROR", and writes the remaining lines to a new file.

Instructions

  1. Use fs.createReadStream to read the file logs.txt in chunks.

  2. Create a transform stream to filter out lines containing the word "ERROR".

  3. Use fs.createWriteStream to write the filtered logs to filtered-logs.txt.

  4. Pipe the streams together for seamless processing.

Sample input

The following are the contents of sample input file logs.txt: