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

99
Views
How to fetch multiple files synchroniously and load them into a single variable

How would you recommend I go about fetching multiple files (in particular, CSV files) and merging them into a single variable? I've tried using the following and I'm pretty sure I got something about the promise syntax/logic wrong, as that is an area I'm fairly new to, but it may be another problem. Here is my current attempt:

fetcher(specURL).then(async (spec) => {
    let rawData;
    if (typeof spec.dataURL === "string") {
        rawData = await fetcher(spec.dataURL);
    } else if (typeof spec.dataURL === "array") {
        rawData = {};
        await spec.dataURL.forEach(async (url, i) => {
            rawData[i] = await fetcher(url);
        });
    }
    console.log(rawData);
}

As you can see I use a spec (specification) json which articulates which URLs to fetch. If it is an array I would like to fetch multiple files into an array.

I'm using my fetcher function, which is the following (any recommendations to improving it are appreciated too!

async function fetcher(url, type) {
let fetched = await fetch(url);
fetched = await fetched.text();
if (type == undefined) {
    type = url.split(".").pop();
}
if (type == "json") {
    fetched = JSON.parse(fetched);
} else if (type == "csv") {
    fetched = Papa.parse(fetched, { header: true }).data;
}
return fetched;

}

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!