bored-baker-20372
07/03/2022, 4:03 AMfunction jsonReader(filePath, cb) {
fs.readFile(filePath, 'utf-8', (err, fileData) => {
if (err) {
return cb && cb(err);
}
try {
const parsedObject = JSON.parse(fileData);
return cb && cb(null, parsedObject);
} catch (err) {
return cb && cb(err);
}
});
}
I am trying to update a json file whenever this script is run. But unfortunately I always get a fs.readFile is not a function error. Have I missed anything here? Applogies if the code entry is too lengthy.