I’ve noticed that arguments are not being recognized in Node.js filesystem when wrapped with ()
. Can anyone explain why this is happening please? My expectation was the even when wrapped in ()
, it will work just like forEach()
function?
const fs = require('fs');
const path = require('path');
const root = path.resolve(__dirname);
fs.readdir(root, (error, filenames) => {
filenames.forEach( filename => {
const filePath = path.join(root, filename);
fs.unlink( (filePath, err) => {
// Throws error saying 'filePath' is not defined..?
});
});
});