Answers for "how to fetch local json file in javascript"

0

how to fetch local json file in javascript

Try to use file system. Don't think reading from a JSON file works like that.

const fs = require('fs');
const json_data = require('../services/contributors.JSON');

fs.readFile(json_data, 'utf8', function (err, data) {
  try {
    data = JSON.parse(data)
    for (let i in data){
    console.log('Name:',data[i].name)
    }
  } catch (e) {
    // Catch error in case file doesn't exist or isn't valid JSON
  }
});
Posted by: Guest on March-18-2021

Code answers related to "how to fetch local json file in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language