I'm not getting the value of Input and Output variables. I have tried using this keyword also in the below code.
it("Final Decoding Tests", () => {
let input = "";
let output = "";
fs.readFile("./test/test_data/booksEncoded.txt", { encoding: "utf-8" }, (err, data) => {
if (!err) {
this.input = data;
} else {
console.log(err);
}
});
fs.readFile("./test/test_data/books.xml", { encoding: "utf-8" }, (err, data) => {
if (!err) {
this.output = data;
} else {
console.log(err);
}
});
console.log(input); // NO OUTPUT
console.log(this.output); //PRINTS undefined
});
I think I have to read the files asynchronously using the done
callback.
My question is:
Why I'm not getting any values for the input and output outside the fs.readFile methods? and Is there any way to read it using done keyword asynchronously?