Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
I can't manage to make a function parsing an XML file to a js object

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!