// Step 1: Import the 'fs' module (File System module)
const fs = require('fs');
// Step 2: Define the path to the directory you want to list
const directoryPath = '/path/to/your/directory';
// Step 3: Use the 'fs.readdir' method to read the contents of the directory
fs.readdir(directoryPath, (err, files) => {
// Step 4: Handle any potential errors
if (err) {
console.error('Error reading directory:', err);
return;
}
// Step 5: Iterate through the array of file names and log them
files.forEach(file => {
console.log(file);
});
});