var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
function readTextFile(file)
{
let rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
let allText = rawFile.responseText;
console.log(allText);
}
}
}
rawFile.send(null);
}
readTextFile("/input.txt");
I want to read a txt file and print it to console but I'm getting undefined. What is the reason for that?
Use toString() method returns the buffer object.