I am making a function that takes a path to an XML file as input and outputs a js object corresponding to the parsed XML. Currently, I have this code :
async function parseXML(pathToFile) {
var fs = require('fs'),
xml2js = require('xml2js');
var parser = new xml2js.Parser();
await fs.readFile(pathToFile, function(err, data) {
parser.parseString(data, function(err, result) {
return result;
});
});
}
res = parseXML(file)
console.log(res)
But it comes out a Promise{} object and I don't know what to do with it. Does anyone have a solution? Thanks alot!
PS: I'm quite new to JS and asynchronous functions are quite difficult to learn. I think the problem comes from the asynchrony but I'm not sure