I am trying to read xml file using fs.I am not able to read file using fs.readFileSync after passing path variable as first paramter to this function. Note:this is in windows machine
xmlFile="C:\Users\xyz\AppData\Local\.proxySettings.xml";
function myFunc(xmlFile) {
let xmlData = fs.readFile(xmlFile);
alert(xmlData);//doesn't print anything
parser = new DOMParser();
xmlDoc = parser.parseFromString(xmlData,"text/xml");
....
....
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<proxy_port>2582</proxy_port>
update in the file
try{
ffile="jdkdkj";
fs.readFileSync(ffile);
}catch(err){
app.console.log(err);
}
Error { errno: -4058, syscall: 'open', code: 'ENOENT', path: 'jdkdkj' }
let xmlData = fs.readFile(xmlFile);which will never work asfs.readFile()is asynchronous and requires a callback as the second argument to communicate back the result. Also, your backslashes in the path have to be double escaped.