Skip to content

Commit e9d4baf

Browse files
StevepurposeMoLow
authored andcommitted
doc: clarify mkdir() recursive behavior
PR-URL: #48109 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent e18c125 commit e9d4baf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

doc/api/fs.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,19 +3179,20 @@ Asynchronously creates a directory.
31793179
The callback is given a possible exception and, if `recursive` is `true`, the
31803180
first directory path created, `(err[, path])`.
31813181
`path` can still be `undefined` when `recursive` is `true`, if no directory was
3182-
created.
3182+
created (for instance, if it was previously created).
31833183
31843184
The optional `options` argument can be an integer specifying `mode` (permission
31853185
and sticky bits), or an object with a `mode` property and a `recursive`
31863186
property indicating whether parent directories should be created. Calling
31873187
`fs.mkdir()` when `path` is a directory that exists results in an error only
3188-
when `recursive` is false.
3188+
when `recursive` is false. If `recursive` is false and the directory exists,
3189+
an `EEXIST` error occurs.
31893190
31903191
```mjs
31913192
import { mkdir } from 'node:fs';
31923193
3193-
// Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
3194-
mkdir('/tmp/a/apple', { recursive: true }, (err) => {
3194+
// Create ./tmp/a/apple, regardless of whether ./tmp and ./tmp/a exist.
3195+
mkdir('./tmp/a/apple', { recursive: true }, (err) => {
31953196
if (err) throw err;
31963197
});
31973198
```

0 commit comments

Comments
 (0)