Skip to content

Documentation fsPromises.readdir: possibly superfluous await #3317

@michaelrommel

Description

@michaelrommel

The documentation at: https://nodejs.org/api/fs.html#fs_fspromises_readdir_path_options provides an example to iterate over the returned file array. It uses the construct:

for await (const file of files)
    console.log(file);

I thought, that this await would only be necessary, if the returned array would contain objects of a class, which provides an asyncIterator, like fs.Dir (https://nodejs.org/api/fs.html#fs_dir_symbol_asynciterator).

Why is this await statement necessary? I would understand, if the example had the options object set to withFileTypes set to true, because in this case the returned array is of type fs.Dirent and not an array of Strings or Buffers. (But even then it is questionable, since also fs.Dirent does not document an asyncIterator.

If this is an error in the documentation, I am happy to open an issue on the node repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions