From b50a6cc54d31dd757bfc332b2ffebffc6452a6be Mon Sep 17 00:00:00 2001 From: Conor ONeill Date: Tue, 28 Jan 2020 16:06:56 +0000 Subject: [PATCH] doc: add example to fs.promises.readdir PR-URL: https://github.com/nodejs/node/pull/31552 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott --- doc/api/fs.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/api/fs.md b/doc/api/fs.md index 8c84e0d229fa13..4c1680191ae563 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -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])`