diff --git a/doc/api/fs.md b/doc/api/fs.md index 4bd7da6de39030..252db1b392f7c0 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1069,6 +1069,38 @@ including subdirectories and files. When copying a directory to another directory, globs are not supported and behavior is similar to `cp dir1/ dir2/`. +### `fsPromises.glob(pattern[, options])` + + + +> Stability: 1 - Experimental + +* `pattern` {string|string\[]} +* `options` {Object} + * `cwd` {string} current working directory. **Default:** `process.cwd()` + * `exclude` {Function} Function to filter out files/directories. Return + `true` to exclude the item, `false` to include it. **Default:** `undefined`. +* Returns: {AsyncIterator} An AsyncIterator that yields the paths of files + that match the pattern. + +```mjs +import { glob } from 'node:fs/promises'; + +for await (const entry of glob('**/*.js')) + console.log(entry); +``` + +```cjs +const { glob } = require('node:fs/promises'); + +(async () => { + for await (const entry of glob('**/*.js')) + console.log(entry); +})(); +``` + ### `fsPromises.lchmod(path, mode)` + +> Stability: 1 - Experimental + +* `pattern` {string|string\[]} + +* `options` {Object} + * `cwd` {string} current working directory. **Default:** `process.cwd()` + * `exclude` {Function} Function to filter out files/directories. Return + `true` to exclude the item, `false` to include it. **Default:** `undefined`. + +* `callback` {Function} + * `err` {Error} + +* Retrieves the files matching the specified pattern. + +```mjs +import { glob } from 'node:fs'; + +glob('**/*.js', (err, matches) => { + if (err) throw err; + console.log(matches); +}); +``` + +```cjs +const { glob } = require('node:fs'); + +glob('**/*.js', (err, matches) => { + if (err) throw err; + console.log(matches); +}); +``` + ### `fs.lchmod(path, mode, callback)` + +> Stability: 1 - Experimental + +* `pattern` {string|string\[]} +* `options` {Object} + * `cwd` {string} current working directory. **Default:** `process.cwd()` + * `exclude` {Function} Function to filter out files/directories. Return + `true` to exclude the item, `false` to include it. **Default:** `undefined`. +* Returns: {string\[]} paths of files that match the pattern. + +```mjs +import { globSync } from 'node:fs'; + +console.log(globSync('**/*.js')); +``` + +```cjs +const { globSync } = require('node:fs'); + +console.log(globSync('**/*.js')); +``` + ### `fs.lchmodSync(path, mode)`