I don't understand a lot about Promises. I have this function to read data in JSON file:
const getData = (fileName) =>
new Promise((resolve, reject) =>
fs.readFile(fileName, 'utf8', (err, data) => {
console.log("Tipo da data:", typeof(data))
return err ? reject(err) : resolve(data);
})
);
I do this:
const hashList = getData('./users/hashList.json')
.then(data => console.log(data))
.catch(error => console.log('Error: ', error));
'./users/hashList.json' is something like that ["2d37c88b9e650846b5eb0d2c0f38ecbf8601f6c5"] I want to know if the hashReceived is in this hashList, I do this:
if(hashList.includes(receivedHash)){
console.log("ok")
}
But when I run the code, I have this error: TypeError: hashList.includes is not a function. When I console hashList, I receive this: Promise { } Someone would help me to resolve that as assynchronous function? I only resolve using readSync, is readSync the only way to resolve that?