For some days I have searched for a working solution to an error
Error: EMFILE, too many open files
It seems that many people have the same proble
For anyone that might still be looking for solutions, using async-await worked fine for me:
fs.readdir( , async (err, filenames) => {
if (err) {
console.log(err);
}
try {
for (let filename of filenames) {
const fileContent = await new Promise((resolve, reject) => {
fs.readFile(, 'utf-8', (err, content) => {
if (err) {
reject(err);
}
resolve(content);
});
});
... // do things with fileContent
}
} catch (err) {
console.log(err);
}
});