Skip to content

Commit ba962bd

Browse files
StevepurposeCeres6
authored andcommitted
doc: clarify mkdir() recursive behavior
PR-URL: nodejs#48109 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent a276ff9 commit ba962bd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

doc/api/fs.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -3198,19 +3198,20 @@ Asynchronously creates a directory.
31983198
The callback is given a possible exception and, if `recursive` is `true`, the
31993199
first directory path created, `(err[, path])`.
32003200
`path` can still be `undefined` when `recursive` is `true`, if no directory was
3201-
created.
3201+
created (for instance, if it was previously created).
32023202
32033203
The optional `options` argument can be an integer specifying `mode` (permission
32043204
and sticky bits), or an object with a `mode` property and a `recursive`
32053205
property indicating whether parent directories should be created. Calling
32063206
`fs.mkdir()` when `path` is a directory that exists results in an error only
3207-
when `recursive` is false.
3207+
when `recursive` is false. If `recursive` is false and the directory exists,
3208+
an `EEXIST` error occurs.
32083209
32093210
```mjs
32103211
import { mkdir } from 'node:fs';
32113212
3212-
// Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
3213-
mkdir('/tmp/a/apple', { recursive: true }, (err) => {
3213+
// Create ./tmp/a/apple, regardless of whether ./tmp and ./tmp/a exist.
3214+
mkdir('./tmp/a/apple', { recursive: true }, (err) => {
32143215
if (err) throw err;
32153216
});
32163217
```

0 commit comments

Comments
 (0)