From 7647954a85aafaaaea714aaca0a803b06fa7e11f Mon Sep 17 00:00:00 2001 From: Stevepurpose Date: Mon, 22 May 2023 01:07:51 +0100 Subject: [PATCH 1/6] doc: clarify mkdir() recursive behavior --- doc/api/fs.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index cc8bce4b0431fa..48aa130aa474c6 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3198,23 +3198,29 @@ 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 the directory was previously created or other issues. 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.That is, if we don't add `recursive` as true and +the file was previously created,we get an EEXIST (error Exist) message telling + us path already exists. ```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) => { +//Note the relative path to `tmp` below ,otherwise path won't be created in our project. + +mkdir('./tmp/a/apple', { recursive: true }, (err) => { if (err) throw err; }); ``` +without `recursive` being set as true it the code above,output shows an error + + On Windows, using `fs.mkdir()` on the root directory even with recursion will result in an error: From 65a190ea55548e65838bce85a59e2a3560e4fc78 Mon Sep 17 00:00:00 2001 From: Stephen Odogwu <105284225+Stevepurpose@users.noreply.github.com> Date: Mon, 22 May 2023 15:40:52 +0100 Subject: [PATCH 2/6] Update doc/api/fs.md Co-authored-by: Rich Trott --- doc/api/fs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 48aa130aa474c6..2aae4522c2cfd5 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3198,7 +3198,7 @@ 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,for instance if the directory was previously created or other issues. +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` From 341eb8cefa5a9dcfbdd77aae122bb89e2dc3c20a Mon Sep 17 00:00:00 2001 From: Stephen Odogwu <105284225+Stevepurpose@users.noreply.github.com> Date: Mon, 22 May 2023 15:41:35 +0100 Subject: [PATCH 3/6] Update doc/api/fs.md Co-authored-by: Rich Trott --- doc/api/fs.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 2aae4522c2cfd5..45960ed4fbe98c 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3211,8 +3211,7 @@ the file was previously created,we get an EEXIST (error Exist) message telling ```mjs import { mkdir } from 'node:fs'; -//Note the relative path to `tmp` below ,otherwise path won't be created in our project. - +// Create ./tmp/a/apple, regardless of whether ./tmp and ./tmp/a exist. mkdir('./tmp/a/apple', { recursive: true }, (err) => { if (err) throw err; }); From 2ca207415aeb2f20b367a4f1dbf543416495f387 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 22 May 2023 08:59:54 -0700 Subject: [PATCH 4/6] Update doc/api/fs.md --- doc/api/fs.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 45960ed4fbe98c..5a3ee741c6caaf 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3204,9 +3204,8 @@ 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.That is, if we don't add `recursive` as true and -the file was previously created,we get an EEXIST (error Exist) message telling - us path already exists. +when `recursive` is false. If `recursive` is false and the directory exists, +an `EEXIST` error occurs. ```mjs import { mkdir } from 'node:fs'; From 1a3c70a49f72dc4402d35fde3ebd882afedfd553 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 22 May 2023 09:00:03 -0700 Subject: [PATCH 5/6] Update doc/api/fs.md --- doc/api/fs.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 5a3ee741c6caaf..ceaa4ba247bf55 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3216,9 +3216,6 @@ mkdir('./tmp/a/apple', { recursive: true }, (err) => { }); ``` -without `recursive` being set as true it the code above,output shows an error - - On Windows, using `fs.mkdir()` on the root directory even with recursion will result in an error: From 040f6df0347176b76d094310c0853edc26c21007 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 22 May 2023 11:43:26 -0700 Subject: [PATCH 6/6] Update doc/api/fs.md --- doc/api/fs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index ceaa4ba247bf55..e95865db7fb200 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3204,7 +3204,7 @@ 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. If `recursive` is false and the directory exists, +when `recursive` is false. If `recursive` is false and the directory exists, an `EEXIST` error occurs. ```mjs