Skip to Content
APImkdtemp

mkdtemp

Create a unique temporary directory with the given prefix. Uses OS random source (/dev/urandom on Unix, BCryptGenRandom on Windows) with up to 10 retries.

Basic usage

import { mkdtemp } from '@vooya/fs' const dir = await mkdtemp('/tmp/myapp-') console.log(dir) // e.g. /tmp/myapp-abc123

Methods

mkdtemp(prefix)

Async. Returns Promise<string> (the created directory path).

ArgumentTypeDescription
prefixstringPrefix for the directory name (e.g. path + trailing separator).

mkdtempSync(prefix)

Sync. Returns string or throws.

Performance

Single syscall plus random generation; on par with Node.js. See Benchmarks.

Notes

  • Prefix: Include a trailing path separator (e.g. os.tmpdir() + '/') so the random part is the last path component; same as Node.js.
  • Cleanup: Caller is responsible for removing the directory when done (e.g. rm(dir, { recursive: true })).
  • Known gap: Missing-parent errors currently have Node-like messages, but do not expose Node-style code, path, and syscall fields yet.
  • Unsupported Node inputs/options: Buffer prefixes, URL prefixes, and the encoding option are not part of the current Vooya FS mkdtemp surface.

Competitor measurements

See the full mkdtemp comparison table for Node 22/24, peer libraries, sync/Promise modes, small and batch workloads, execution routes and measurement limits.

Last updated on