I have read some question about callback. But still can't understand. I write this code to store file into an array.
var admList; // The array I want to store in
let readList =(fPath, callback)=>fs.readFile(fPath, 'utf8', (err, fd) => {
if (err) console.error(fPath+'does not exist');
callback(fd); // set a callback
});
readList('admList', function (fd) {
admList = fd.toString().trim().split('\n'); //using it
});
console.log(admList); // undefined
Am I already using a callback function? Why in the console it's still undefined?