From 64cd3a6e9589d2eb32594ea0633ab5e49cb95b2b Mon Sep 17 00:00:00 2001 From: soreavis <263610811+soreavis@users.noreply.github.com> Date: Tue, 18 Aug 2026 17:15:47 +0200 Subject: [PATCH] doc: clarify how fs.Dirent file types are determined The file type of a directory entry returned by fs.readdir() or fs.opendir() is the type reported by the operating system's directory listing. Node.js falls back to lstat() only when the reported type is unknown, and some file systems may report a type that differs from what lstat() would return. Document this in the fs.Dirent class introduction, with fs.lstat() as the accurate alternative. Fixes: https://github.com/nodejs/node/issues/30646 Signed-off-by: Julian Soreavis PR-URL: https://github.com/nodejs/node/pull/64532 Reviewed-By: Luigi Pinca Reviewed-By: Jason Zhang --- doc/api/fs.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/api/fs.md b/doc/api/fs.md index 1fe87bf5a48..60a90b4f255 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -7371,6 +7371,13 @@ Additionally, when [`fs.readdir()`][] or [`fs.readdirSync()`][] is called with the `withFileTypes` option set to `true`, the resulting array is filled with {fs.Dirent} objects, rather than strings or {Buffer}s. +When a directory is read, such as with [`fs.readdir()`][] or +[`fs.opendir()`][], the file type of each entry is the type reported by the +operating system and may depend on the file system; for example, some file +systems may report a type that differs from what [`fs.lstat()`][] returns. +Node.js calls [`fs.lstat()`][] on such an entry only when the reported type +is unknown. Use [`fs.lstat()`][] when an accurate file type is required. + #### `dirent.isBlockDevice()`