Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!