fs.readdir()
The Node.js function that lists the entries of a directory, optionally with their types and optionally including every subdirectory.
In more detail
With { withFileTypes: true } it returns Dirent objects that already know whether each entry is a file or a directory. With { recursive: true } it walks the whole tree in one call.
Related terms
- Dirent — The object Node.js uses for one directory entry, with its name and methods such as isFile() and isDirectory().
- directory walk — Visiting every file and folder below a starting directory, as a build tool or file indexer does.
- node:fs — The built-in Node.js module for working with files and folders, in promise, callback and synchronous forms.
Taught in
- Directory Traversal: Recursive Readdir & fs.watch — Node.js Internals & Backend Services