I was using chokidar for the first time and I was trying to get all the file names in a directory and push them to an array. Chokidar successfully gets the file names but when I push them to array the names are not being registered. Or maybe they are being registered then being overwritten by an empty path when chokidar checks for updates. Either way, how can I get all the file names in an array. Any help is appreciated. Thanks in advance.
const chokidar = require('chokidar');
var currentData = []
chokidar.watch('./dirPATH').on('all', (event, path) => {
//what I tried
if (path != '' && path != ' ' && path != null && path != undefined) {
currentData.push(path);
}
console.log(path) //prints path correctly
});
console.log(currentData) //prints empty array
//expected print array with items of file names aquired by chokidar