# with-tmp-dir-promise

> Utilities to use tmp temporary directories with promise-based code

Latest version **1.1.2** (published 2020-04-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install with-tmp-dir-promise
pnpm add with-tmp-dir-promise
yarn add with-tmp-dir-promise
bun add with-tmp-dir-promise
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2020-04-13 |
| First published | 2018-04-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Rapidfacture GmbH |
| Maintainers | felix_furtmayr, jochenh, max_speedy, rf-alex, rf-bernhard, ulikoehler |

## Links

- npm: https://www.npmjs.com/package/with-tmp-dir-promise
- Repository: https://github.com/Rapidfacture/with-tmp-dir-promise
- Homepage: https://github.com/Rapidfacture/with-tmp-dir-promise/blob/master/README.md
- Issues: https://github.com/Rapidfacture/with-tmp-dir-promise/issues
- npm.io page: https://npm.io/package/with-tmp-dir-promise

## Dependencies (1)

- [tmp](https://npm.io/package/tmp.md) 0.0.33

## Recent versions

- 1.1.2 (latest) — 2020-04-13
- 1.1.1 — 2019-03-03
- 1.1.0 — 2019-03-03
- 1.0.3 — 2018-04-19
- 1.0.2 — 2018-04-19
- 1.0.1 — 2018-04-13
- 1.0.0 — 2018-04-06

## README

# with-tmp-dir-promise
Run a promise-based function with a temporary directory, deleting it afterwards.

Requires NodeJS 8+.

# Installation

```sh
npm install --save with-tmp-dir-promise
```

# Usage example

```js
const {WithTempDir} = require('with-tmp-dir-promise');

WithTempDir(function (tmpdir) {
    // tmpdir is a string like '/tmp/q3q235',
    // pointing to an existing temporary directory

    // Your code goes here

    // When this function returns, the tmp directory will be deleted
    // Remember to return a Promise here!
    return Promise.resolve("foobar"); // Example
}).then(function(arg) {
    // arg === 'foobar'

    // tmpdir, including all files in the directory,
    // is deleted here
});
```

# WithTempDir documentation

```js
/**
 * Run the given callback with a newly created temporary directory,
 * automatically cleaning up once the promise
 * This function returns a promise that resolves of rejects depending on
 * A failure in creating the temporary directory causes
 * immediate rejection without calling the callback.
 * @param {*} callback A function(tmpPath) retuning a promise
 * @param {*} opts Options for the tmp library. Default: Also delete files in the directory.
 * Also supports cleanupAfter opt: If true, cleanup after resolving/rejecting the returned Promise.
 * If false (default), cleanup before
 */
function WithTempDir (callback, opts = {unsafeCleanup: true, cleanupAfter: false}) {
    // ...
}
```

---
_Source: https://npm.io/package/with-tmp-dir-promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
