2021 update: the ambiguity has been fixed in nodejs doc in an April 2021 commit
Edit: This is essentially an issue with node docs. See discussion here.
I'm trying the fs.Dir class which was added since node v12.12:
// hello-world.js
const fs = require('fs');
(async function () {
const dir = await fs.promises.opendir(__dirname);
for await (const dirent of dir) {
console.log('name:', dirent.name, 'isDir:', dirent.isDirectory());
}
return dir.close();
})();
$ node hello-world.js
It seems to be working as expected, which logs out info of each file in the directory (not missing a single one), but in the end it throws (node:3218) UnhandledPromiseRejectionWarning: Error [ERR_DIR_CLOSED]: Directory handle was closed at Dir.close (internal/fs/dir.js:161:13)
. What am I doing wrong?