The first function results in error and the second one is working as behaved, why? Why does callback make working correct?Function 1static fetchAll() {const p = path.join(path.dirname(process.mainModule.filename), 'data', 'products.json');fs.readFile(p, (err, fileContent) => {if (err) {return [];}return JSON.parse(fileContent);});}Function 2static fetchAll(cb) {const p = path.join(path.dirname(process.mainModule.filename), 'data', 'products.json');fs.readFile(p, (err, fileContent) => {if (err) {cb([]);}cb(JSON.parse(fileContent));});}
Submitted July 02, 2019 at 07:32PM by tensorhere
No comments:
Post a Comment