From 5bdfc730438da32852a6199b1bbe87f71a729660 Mon Sep 17 00:00:00 2001 From: Conor ONeill Date: Tue, 28 Jan 2020 16:06:56 +0000 Subject: [PATCH 1/3] doc: Add example to fs.promises.readdir --- doc/api/fs.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/api/fs.md b/doc/api/fs.md index 9ed072ad1e4871..db00c5e4e73ec1 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -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 using async iteration: + +```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])`