I have been starting to learn the basics of "fs" on node.js, and ran into a small problem that I am not sure how to fix. I declare a variable in the first function, but try to change it in the second. I know that this will not update the value in the nested function, however, I am not sure how I can get it from the second function to return it with the first function.
Code:
function fetchUserData(id,fetchedData){
var returnValue
fs.readFile("./mainData.json","utf-8",(err,jsonString) => {
if (err) {
console.log("Error while retrieving data: " + err);
} else {
try {
const currentData = JSON.parse(jsonString);
if (currentData) {
if (currentData["User" + id]){
returnValue = [currentData, true];
} else {
returnValue = [currentData, false];
}
}
} catch(err) {
console.log("Error while parsing data to read: " + err);
};
};
});
return returnValue;
};