mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
doc: add example to fs.promises.readdir
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
f0ffa4cb80
commit
b50a6cc54d
1 file changed
+12
@@ -4941,6 +4941,18 @@ will be passed as `Buffer` objects.
|
||||
If `options.withFileTypes` is set to `true`, the resolved array will contain
|
||||
[`fs.Dirent`][] objects.
|
||||
|
||||
```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
|
||||
|
||||
Reference in new issue
Block a user