nodejs read all files in directory code example
Example 1: node get all files in folder
fs.readdir('./', (err, files) => {
files.forEach(file => {
})});
Example 2: node list files in directory
const path = require('path');
const fs = require('fs');
const directoryPath = path.join(__dirname, 'Documents');
fs.readdir(directoryPath, function (err, files) {
if (err) {
return console.log('Unable to scan directory: ' + err);
}
files.forEach(function (file) {
console.log(file);
});
});
Example 3: how to read all files in a folder in node js
fs.readdir('./', (err, files) => {
files.forEach(file => {
}});