I have developed a script in JavaScript for the purpose of parsing log files and extracting relevant information. The script functions as expected for smaller log files, however, when applied to log files exceeding 1 GB in size, it results in the following error: 'Cannot create a string longer than 0x1fffffe8 characters.'
I would appreciate any recommendations or strategies for optimizing my code and resolving this issue, in order to enable it to handle larger log files effectively.
For context, the initial part of my code involves storing the contents of the log file in a lines variable, as shown below:
const lines = fileContents.split("\n");
fs.readFile("./my_file.log", "utf8", (err, data) => {
if (err) throw err;
const lines = data.split("\n");
console.log(lines);
})