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

202
Views
What's the right way to load json files in browsers

I have built a node library loading json files like this

var FILE_PATH = path.join(
  __dirname,
  '../data/data.json'
);

function loadMyJsonFile() {
  return JSON.parse(
    fs.readFileSync(
      FILE_PATH,
      constants.DEFAULT_ENCODING
    )
  );
}

The code works fine on server side. I see this error in Chrome console when the function is executed in browser.

Uncaught TypeError: fs.readFileSync is not a function

I googled a bit and I don't think I can use fs in browser code. What's the right way of loading json files in browser?

over 4 years ago · Santiago Trujillo
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!