npm.io
3.0.0 • Published 4 years ago

@m59/use-tmp-dir

Licence
ISC
Version
3.0.0
Deps
1
Size
5 kB
Vulns
0
Weekly
0

@m59/use-tmp-dir

Takes a function and calls it with a path to a temporary directory. The temporary directory is removed after the function completes, or if the process exits meanwhile.

import { use_tmp_dir } from '@m59/use-tmp-dir'
import { access, writeFile } from 'node:fs/promises'
import { join as join_path } from 'node:path'

const removed_tmp_dir = await use_tmp_dir(
	async tmp_dir => {
		await writeFile(join_path(tmp_dir, 'some-file.txt'), 'some contents')
		return tmp_dir
	}
)

const error = await access(removed_tmp_dir)
	.catch(error => error)
error.code // => 'ENOENT'

Keywords