Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e9d4baf

Browse filesBrowse files
StevepurposeMoLow
authored andcommitted
doc: clarify mkdir() recursive behavior
PR-URL: #48109 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent e18c125 commit e9d4baf
Copy full SHA for e9d4baf

File tree

Expand file treeCollapse file tree

1 file changed

+5
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-4
lines changed
Open diff view settings
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+5-4Lines changed: 5 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.