OS
os.tmpdir()
Returns the default temporary directory. Create a unique owned subdirectory with mkdtemp before writing scratch files; never assume a predictable filename is exclusive. Tested on Node.js 22.16.0. Example output (one line per entry): ["true"].
Formal Syntax & Structure
nodejs syntaxnodejs
os.tmpdir()Return Value
string
Temporary directory path.
Working Example
Example Snippetnodejs
import os from 'node:os';import { mkdtemp, rm } from 'node:fs/promises';import { join, isAbsolute } from 'node:path';const dir = await mkdtemp(join(os.tmpdir(), 'bm-'));try { console.log(isAbsolute(dir));}finally { await rm(dir, { recursive: true, force: true });}