index.js:
const fs = require(‘fs’);
let data = fs.readFileSync(‘./data.json’, ‘utf-8’)
console.log(data)
data.json
[
{
“id”: 1,
“name”: “Limit”,
“score”: 95
},
{
“id”: 2,
“name”: “Skiler”,
“score”: 90
}
]
error message:
node:internal/fs/utils:351
throw err;
^
Error: ENOENT: no such file or directory, open ‘\\?\D:\Tutorial\data.json’
at readFileSyncUtf8 (node:internal/fs/read/utf8:20:3)
at Object.readFileSync (node:fs:467:12)
at Object.<anonymous> (d:\Tutorial\Belajar-menjadi-fullstack-web-developer\Intermediate\4. JavaScript Object Notation\index.js:3:15)
at Module._compile (node:internal/modules/cjs/loader:1233:14)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47 {
errno: -4058,
syscall: ‘open’,
code: ‘ENOENT’,
path: ‘\\\\?\\D:\\Tutorial\\data.json’
}