Skip to content

Commit b50a6cc

Browse files
conorocodebytere
authored andcommitted
doc: add example to fs.promises.readdir
PR-URL: #31552 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent f0ffa4c commit b50a6cc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

doc/api/fs.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4941,6 +4941,18 @@ will be passed as `Buffer` objects.
49414941
If `options.withFileTypes` is set to `true`, the resolved array will contain
49424942
[`fs.Dirent`][] objects.
49434943

4944+
```js
4945+
const fs = require('fs');
4946+
4947+
async function print(path) {
4948+
const files = await fs.promises.readdir(path);
4949+
for (const file of files) {
4950+
console.log(file);
4951+
}
4952+
}
4953+
print('./').catch(console.error);
4954+
```
4955+
49444956
### `fsPromises.readFile(path[, options])`
49454957
<!-- YAML
49464958
added: v10.0.0

0 commit comments

Comments
 (0)