Skip to content

Commit fab676e

Browse files
authored
doc: add fspromises mkdir example
Signed-off-by: Tierney Cyren <hello@bnb.im> PR-URL: nodejs#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>
1 parent 741ed0f commit fab676e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doc/api/fs.md

+28
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,34 @@ property indicating whether parent directories should be created. Calling
10551055
`fsPromises.mkdir()` when `path` is a directory that exists results in a
10561056
rejection only when `recursive` is false.
10571057
1058+
```mjs
1059+
import { mkdir } from 'node:fs/promises';
1060+
1061+
try {
1062+
const projectFolder = new URL('./test/project/', import.meta.url);
1063+
const createDir = await mkdir(path, { recursive: true });
1064+
1065+
console.log(`created ${createDir}`);
1066+
} catch (err) {
1067+
console.error(err.message);
1068+
}
1069+
```
1070+
1071+
```cjs
1072+
const { mkdir } = require('node:fs/promises');
1073+
const { resolve, join } = require('node:path');
1074+
1075+
async function makeDirectory() {
1076+
const projectFolder = join(__dirname, 'test', 'project');
1077+
const dirCreation = await mkdir(projectFolder, { recursive: true });
1078+
1079+
console.log(dirCreation);
1080+
return dirCreation;
1081+
}
1082+
1083+
makeDirectory().catch(console.error);
1084+
```
1085+
10581086
### `fsPromises.mkdtemp(prefix[, options])`
10591087
10601088
<!-- YAML

0 commit comments

Comments
 (0)