os.tmpdir()
Returns the operating system default directory for temporary files.
Syntax
os.tmpdir() Returns
string — The absolute path of the temp directory.
Examples
import { tmpdir } from 'node:os';
console.log(tmpdir());
Output
/var/folders/xy/tmp
import { tmpdir } from 'node:os';
import { mkdtemp } from 'node:fs/promises';
import { join } from 'node:path';
const dir = await mkdtemp(join(tmpdir(), 'build-'));
console.log(dir);
Output
/tmp/build-a1b2c3
Notes
Pair with `fs.mkdtemp` to create a unique scratch directory; never
use a fixed temp filename (predictable paths are a security risk).
Temp contents may be cleared by the OS at any time.