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

148
Vistas
Extracting data using fetch in Javascript

I am trying to read a locally stored text file using javascript. I need to pass the information stored on the text file to pass through evaluations for test result. Since I could not access the text file directly, I have hosted it on to a local server and trying to fetch data using the URL.

Here is how my code looks like -

const mediaFile = 'http://localhost:8080/' + fileName; 
function MediaInfo(file) {
  fetch(file)
  .then(function (response) {
    response.text();
  })
 .then(function (data) {
   console.log(data);
   return response.data();
 });
}

const a = MediaInfo(mediaFile);
await browser.expect(a).eql(44);

    });

But the calling of function MediaInfo(mediaFile) returns undefined. Any idea why I cant get the data returned??

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The function inside the second then is returning some data, but MediaInfo itself isn't returning anything.

Since you have one await already, I'd suggest going fully async/await:

async function MediaInfo(file) {
  const response = await fetch(file);
  const text = await response.text();
  console.log(text);
  return text;
}

Also note that in order to avoid variables storing Promises, you'd probably want to change to

const a = await MediaInfo(mediaFile);
about 4 years ago · Juan Pablo Isaza Denunciar
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