1// in example.json
2{
3 "name": "testing"
4}
5
6// in app.js :
7
8// method 1
9const data = require('./example.json');
10
11// method 2: (ES6/ES2015)
12import * as data from './example.json';
13
14const { name } = data;
15console.log(name); // output 'testing'
1const fs = require('fs');
2
3fs.readFile('./customer.json', 'utf8', (err, jsonString) => {
4 if (err) {
5 console.log("File read failed:", err)
6 return
7 }
8 console.log('File data:', jsonString)
9})
1fs.readFile(filePath, function (error, content) {
2 var data = JSON.parse(content);
3 console.log(data.collection.length);
4});
5