From e9d4baf770da3dd0480e3328e5d0f77e3b613e57 Mon Sep 17 00:00:00 2001 From: Stephen Odogwu <105284225+Stevepurpose@users.noreply.github.com> Date: Wed, 24 May 2023 18:00:37 +0100 Subject: [PATCH] doc: clarify mkdir() recursive behavior PR-URL: https://github.com/nodejs/node/pull/48109 Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca --- doc/api/fs.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index ab6bcf3d3716c7..b850431758694f 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3179,19 +3179,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; }); ```