Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Add example to fs.promises.readdir #31552

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4929,6 +4929,20 @@ will be passed as `Buffer` objects.
If `options.withFileTypes` is set to `true`, the resolved array will contain
[`fs.Dirent`][] objects.

Example iterating over a directory listing:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably omit this line and simply show the example code. If you want to include // Iterate over a directory listing. as a comment in the example code, that would be better IMO. The example code and surrounding text should be related but independent.

jasnell marked this conversation as resolved.
Show resolved Hide resolved

```js
const fs = require('fs');

async function print(path) {
const files = await fs.promises.readdir(path);
for (const file of files) {
console.log(file);
}
}
print('./').catch(console.error);
```

### `fsPromises.readFile(path[, options])`
<!-- YAML
added: v10.0.0
Expand Down