I have to read data from file and then verify if the data email matches. Once it does I use a boolean to store the value. I get output as "It matches" but the user variable is still 'false', which should become true.
let user = false;
const filename = path.resolve(__dirname, "../../users.txt");
newvar = fs.readFile(filename, "utf8", function(err, data) {
if (err) {
console.log(err);
}
const lines = data.split("\n");
for (i = 0; i < lines.length; i++) {
fileArray = lines[i].split("|");
fileName = fileArray[0];
fileEmail = fileArray[1];
filePasswordHash = fileArray[2];
if (email === fileEmail) {
console.log("It Matches");
user = true;
}
}
});
console.log(user);