tmpDir
Less than 1 minute
function tmpDir(options): Promise<TmpDirHelper>
Creates a temporary directory asynchronously.
Parameters
Parameter | Type | Description |
---|---|---|
| Options for creating the temporary directory. |
Returns
Promise
<TmpDirHelper
>
A promise that resolves to a TmpDirHelper.
Example
// Create a temporary directory with a custom prefix
const dir = await tmpDir({ prefix: 'my-temp-dir' });
console.log('Temporary directory created at:', dir.root);
// Check if a file exists in the temporary directory
const exists = await dir.exists('some-file.txt');
console.log('File exists:', exists);
// Clean up the temporary directory
await dir.clean();
console.log('Temporary directory cleaned:', dir.cleaned());
// Track the temporary directory for automatic cleanup on process exit
dir.track();
console.log('Temporary directory tracked:', dir.tracked());
// Untrack the temporary directory
dir.untrack();
console.log('Temporary directory untracked:', dir.tracked());