Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTierney Cyren <hello@bnb.im>2022-06-12 12:33:29 +0300
committerGitHub <noreply@github.com>2022-06-12 12:33:29 +0300
commitfab676ec5536e5fe70d89ff78d366e90d7980627 (patch)
tree3a2055307fe65eb6fd60dccf070b6c8aadff8b21 /doc/api/fs.md
parent741ed0f2652c88391ccf092663821408c8d4d338 (diff)
doc: add fspromises mkdir example
Signed-off-by: Tierney Cyren <hello@bnb.im> PR-URL: https://github.com/nodejs/node/pull/40843 Reviewed-By: Adrian Estrada <edsadr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/fs.md')
-rw-r--r--doc/api/fs.md28
1 files changed, 28 insertions, 0 deletions
diff --git a/doc/api/fs.md b/doc/api/fs.md
index 2f987829ccf..167712f1643 100644
--- a/doc/api/fs.md
+++ b/doc/api/fs.md
@@ -1055,6 +1055,34 @@ property indicating whether parent directories should be created. Calling
`fsPromises.mkdir()` when `path` is a directory that exists results in a
rejection only when `recursive` is false.
+```mjs
+import { mkdir } from 'node:fs/promises';
+
+try {
+ const projectFolder = new URL('./test/project/', import.meta.url);
+ const createDir = await mkdir(path, { recursive: true });
+
+ console.log(`created ${createDir}`);
+} catch (err) {
+ console.error(err.message);
+}
+```
+
+```cjs
+const { mkdir } = require('node:fs/promises');
+const { resolve, join } = require('node:path');
+
+async function makeDirectory() {
+ const projectFolder = join(__dirname, 'test', 'project');
+ const dirCreation = await mkdir(projectFolder, { recursive: true });
+
+ console.log(dirCreation);
+ return dirCreation;
+}
+
+makeDirectory().catch(console.error);
+```
+
### `fsPromises.mkdtemp(prefix[, options])`
<!-- YAML