From 7647954a85aafaaaea714aaca0a803b06fa7e11f Mon Sep 17 00:00:00 2001 From: Stevepurpose Date: Mon, 22 May 2023 01:07:51 +0100 Subject: [PATCH 1/9] 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/9] 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/9] 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/9] 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/9] 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/9] 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 From 960e3266d007d015f166f33c34c51f8ced9d2976 Mon Sep 17 00:00:00 2001 From: Stevepurpose Date: Tue, 6 Jun 2023 02:14:29 -0700 Subject: [PATCH 7/9] don't throw errors in error first callbacks,read Error-first callbacks under Errors --- doc/api/fs.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index e95865db7fb200..c5f9e2b4131699 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3212,7 +3212,10 @@ import { mkdir } from 'node:fs'; // Create ./tmp/a/apple, regardless of whether ./tmp and ./tmp/a exist. mkdir('./tmp/a/apple', { recursive: true }, (err) => { - if (err) throw err; + if (err) { + console.log(err) + return + } }); ``` @@ -3315,7 +3318,10 @@ mkdtemp(tmpDir, (err, directory) => { // This method is *CORRECT*: import { sep } from 'node:path'; mkdtemp(`${tmpDir}${sep}`, (err, directory) => { - if (err) throw err; + if (err) { + console.log(err) + return + } console.log(directory); // Will print something similar to `/tmp/abc123`. // A new temporary directory is created within @@ -3659,7 +3665,10 @@ Asynchronously reads the entire contents of a file. import { readFile } from 'node:fs'; readFile('/etc/passwd', (err, data) => { - if (err) throw err; + if (err) { + console.log(err) + return + } console.log(data); }); ``` From 7e55aa3ca68d7e5c565b6129eb1ae0cf1e2723ac Mon Sep 17 00:00:00 2001 From: Stevepurpose Date: Tue, 6 Jun 2023 03:16:41 -0700 Subject: [PATCH 8/9] supported only by Firefox --- doc/api/errors.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index c0952792727e53..6e4df3f6035f07 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -409,12 +409,15 @@ The location information will be one of: its dependencies. The string representing the stack trace is lazily generated when the -`error.stack` property is **accessed**. +`error.stack` property is **accessed**. The number of frames captured by the stack trace is bounded by the smaller of `Error.stackTraceLimit` or the number of available frames on the current event loop tick. +However `error.stack` does not work on Microsoft,works only on Firefox . + + ## Class: `AssertionError` * Extends: {errors.Error} From d37a985e836df035f6196dcc570b3668978bff42 Mon Sep 17 00:00:00 2001 From: Stevepurpose Date: Tue, 6 Jun 2023 03:30:25 -0700 Subject: [PATCH 9/9] doesn't create if it exists --- 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 c5f9e2b4131699..f38da4ea72e946 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3210,7 +3210,7 @@ an `EEXIST` error occurs. ```mjs import { mkdir } from 'node:fs'; -// Create ./tmp/a/apple, regardless of whether ./tmp and ./tmp/a exist. +// Create ./tmp/a/apple. mkdir('./tmp/a/apple', { recursive: true }, (err) => { if (err) { console.log(err)