Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda