const filePaths = /*здесь функция с readdir */;
return filePaths.map(path => readFile(path));
const fs = require('fs');
const path = require('path');
async function readDirFiles(dir) {
const filePaths = await fs.promises.readdir(dir, {withFileTypes: true});
return await Promise.all(
filePaths
.filter(e => e.isFile())
.map(async (e) => {
const p = path.join(dir, e.name)
return {
path: p,
content: await fs.promises.readFile(p, {encoding: 'utf8'})
};
})
);
}
readDirFiles('.')
.then(files => {
console.log(files);
})
.catch(err =>
console.error(err)
);