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

259
Visualizações
Code being skipped over in node async fs.readFile

enter image description here

I'm trying to store an array of objects , with each object containing an array and an index (called 'column'). the column is string that looks like

'0:lubbock:LW8-12$'

In the main file I am calling:

const tbdObj = await myFunctions.getFromStorageBy(mycolumn);

I want to search through the json in the file 'storage.json' for the object that matches the index (there should be only 1).

async function getFromStorageBy(index) {
  let match;
  fs.readFile("storage.json", function (err, data) {
    // Display the file content
    // console.log(index);
    const jsonArray = JSON.parse(data);
    const matches = jsonArray.filter(obj => obj.column == index);
    console.log('matches');
    console.log(matches);
    match = matches.pop();
    console.log(match);
  });
    return match;
}

The program appears to skip over the readfile block and match is undefined when I try to return it. What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
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