read directory in node js
const fs = require('fs');
const directoryPath = './path/to/your/directory';
// Read the contents of the directory
fs.readdir(directoryPath, (err, files) => {
if (err) {
console.error('Error reading directory:', err);
return;
}
// Iterate over the list of files in the directory
files.forEach((file) => {
// Print the name of each file in the directory
console.log(file);
});
});