I wanted to get line content in a file that contains a string in discord js node.
Something like this:
If (file contains("string")){
console.log(line content)
}
like, if one of the lines in the file contains the string. It's gonna send the line that contains the string to the console.
So all you need is to split the file content by new line and iterate over the lines to find the date like so:
const testFolder = './logs/Chatlogs';
const fs = require('fs');
const path = require('path');
fs.readdirSync(testFolder).forEach(file => {
console.log(file);
// read the file content
var content = fs.readFileSync(path.join(testFolder, file));
var date = '20211203';
var lines = content.split('\n');
lines.forEach(l => {
if(l.indexOf(date) > -1)
console.log('Found it:', l);
});
});