get all files in directory javascript code example
Example 1: node get all files in folder
fs.readdir('./', (err, files) => {
files.forEach(file => {
})});
Example 2: node js get files in dir
const path = require('path');
const fs = require('fs');
fs.readdir(
path.resolve(__dirname, 'MyFolder'),
(err, files) => {
if (err) throw err;
for (let file of files) {
console.log(file);
}
}
);
Example 3: javascript get list of files in directory
var fs = require('fs');
var files = fs.readdirSync('/downloads');