Skip to content

Commit

Permalink
doc: clarify mkdir() recursive behavior
Browse files Browse the repository at this point in the history
PR-URL: nodejs#48109
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Stevepurpose authored and Ceres6 committed Aug 14, 2023
1 parent a276ff9 commit ba962bd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3198,19 +3198,20 @@ Asynchronously creates a directory.
The callback is given a possible exception and, if `recursive` is `true`, the
first directory path created, `(err[, path])`.
`path` can still be `undefined` when `recursive` is `true`, if no directory was
created.
created (for instance, if it was previously created).
The optional `options` argument can be an integer specifying `mode` (permission
and sticky bits), or an object with a `mode` property and a `recursive`
property indicating whether parent directories should be created. Calling
`fs.mkdir()` when `path` is a directory that exists results in an error only
when `recursive` is false.
when `recursive` is false. If `recursive` is false and the directory exists,
an `EEXIST` error occurs.
```mjs
import { mkdir } from 'node:fs';
// Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
mkdir('/tmp/a/apple', { recursive: true }, (err) => {
// Create ./tmp/a/apple, regardless of whether ./tmp and ./tmp/a exist.
mkdir('./tmp/a/apple', { recursive: true }, (err) => {
if (err) throw err;
});
```
Expand Down

0 comments on commit ba962bd

Please sign in to comment.