Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda