Skip to content

Commit

Permalink
doc: add fspromises mkdir example
Browse files Browse the repository at this point in the history
Signed-off-by: Tierney Cyren <hello@bnb.im>

PR-URL: #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>
  • Loading branch information
bnb authored and danielleadams committed Jun 13, 2022
1 parent b05cea5 commit e30d4c1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,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
Expand Down

0 comments on commit e30d4c1

Please sign in to comment.