I have seen different method to read JSON files from localy in Nodejs. like this;
Method
using fs library
Sync
var fs = require('fs'); var obj = JSON.parse(fs.readFileSync('file', 'utf8'));
Async:
var fs = require('fs'); var obj; fs.readFile('file', 'utf8', function (err, data) { if (err) throw err; obj = JSON.parse(data); });
Method
using require()
let data = require('/path/file.json');
Method
using Ajax request How to retrieve data from JSON file using Jquery and ajax?
There might have any other ways. But I heard when reading JSON file using Method 1 is efficient than other methods.
I'm developing a module where I have to read a JSON file when each client side request and Im currently using Method 1. This is banking application and performance is matter. so help me to find which way is good to use this senario?
Thanks , Any help would be appreciated!