import json file with nodejs code example
Example 1: read json file nodejs
const fs = require('fs');
const path = require('path');
let rawdata = fs.readFileSync(path.resolve(__dirname, 'student.json'));
let student = JSON.parse(rawdata);
console.log(student);
Example 2: read json file node js
function readJsonFile(file) {
let bufferData = fs.readFileSync(file)
let stData = bufferData.toString()
let data = JSON.parse(stData)
return data
}