node js fs readdir to include folders code example
Example 1: 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 2: nodejs readdir
const fs = require("fs")
fs.readdir("./myfolder", (err, data) => {
if(err) throw err
console.log(data)
})