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

237
Views
Accessing local json files from the browser using NodeJs backend

I am working on a react application that takes the json file path as a parameter to render the json data in my ui. Accessing local files from the browser is restricted, so how can I create a backend server to retrieve my local json files and serve them to the browser?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

To access local json files in your swagger application, you need to use express - as the browser cannot access your local file system. You can create an endpoint, i.e. '/swagger', that will allow you to serve the files from the directory provided. In the urls parameter, you will use '/swagger/name.json', rather than the local path. Create a driver.js file with the following content:

var express = require('express');
var app = express();
app.use('/swagger', express.static('/path/to/local/files'));
app.listen(3000);
about 4 years ago · Santiago Trujillo Report

0

you can boot up a local server using express, and use the fs module to access file content

const fs = require('fs');
const file_content = fs.readFileSync('./{file_name}', 
    '{content_formate}').toString();

// For show the data on console
console.log(file_content);

To create a server that is listening on port 3000, use

const express = require('express')
const fs = require('fs');
const app = express()
const port = 3000

app.get('/', (req, res) => {


  const file_content = fs.readFileSync('./{file_name}', 
    '{content_formate}').toString();
  res.send(file_content)
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

something like this

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