File system
fs/promises.mkdir()
Creates a directory; recursive mode can create missing parent directories. Tested on Node.js 22.16.0. Recursive mode does not turn a file into a directory; still handle errors.
Formal Syntax & Structure
nodejs syntaxnodejs
fsPromises.mkdir(path[, options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| path | string | Buffer | URL | Path to a lab-owned file or directory. |
| options | object | integer | Recursive flag and mode, or mode alone. |
Return Value
Promise<string | undefined>
First created directory in recursive mode, or undefined when none is reported.
Working Example
Example Snippetnodejs
import * as fs from 'node:fs/promises';import { join } from 'node:path';import { tmpdir } from 'node:os';const dir=await fs.mkdtemp(join(tmpdir(),'bytemind-ref-'));try { const target=join(dir,'catalog','drafts'); await fs.mkdir(target,{recursive:true}); console.log((await fs.stat(target)).isDirectory());} finally { await fs.rm(dir,{recursive:true,force:true}); }