I am attempting to read a flat (text) file and return the number of lines that start with a "1" or a "2".
The issue i'm seeing is that the "recordCount" returns a 0. Would like the recordCount variable to be incremented by 1 every time the condition is met.
export async function getReportRecordCount(finalFile: string, filePath: string) {
try {
let recordCount = 0;
const rl = readline.createInterface({
input: fs.createReadStream(`${filePath}/${finalFile}`),
output: process.stdout
});
rl.on("line", (line) => {
if (line.toString().startsWith("1" || "2")) {
recordCount++;
}
});
return recordCount;
}
}