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

258
Vistas
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 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