withTempDir
Creates a fresh temporary directory under the OS temp root, runs fn with its path, and
always removes it (recursively) afterward — including when fn throws.
Available since v3.1.1
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
prefix | string | Prepended to the generated directory name, to make it identifiable |
fn | function | Receives the temp directory’s absolute path; its (possibly synchronous) return value is returned |
Returns
Section titled “Returns”Promise<T> — Whatever fn returns or resolves to
Examples
Section titled “Examples”Do work in a scratch directory that always gets cleaned up
Section titled “Do work in a scratch directory that always gets cleaned up”The directory is removed once fn resolves, even if fn throws.
