# tempfile

> Get a random temporary file path

Latest version **6.0.1** (published 2026-01-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install tempfile
pnpm add tempfile
yarn add tempfile
bun add tempfile
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.0.1 |
| Published | 2026-01-25 |
| First published | 2013-12-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 2 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 81 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | temp, temporary, tempfile, file, path, random, uuid |

## Links

- npm: https://www.npmjs.com/package/tempfile
- Repository: https://github.com/sindresorhus/tempfile
- Homepage: https://github.com/sindresorhus/tempfile#readme
- Issues: https://github.com/sindresorhus/tempfile/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/tempfile

## Dependencies (2)

- [temp-dir](https://npm.io/package/temp-dir.md) ^3.0.0
- [is-safe-filename](https://npm.io/package/is-safe-filename.md) ^0.1.1

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 6.0.1 (latest) — 2026-01-25
- 6.0.0 — 2026-01-23
- 5.0.0 — 2023-02-12
- 4.0.0 — 2021-06-08
- 3.0.0 — 2019-04-28
- 2.0.0 — 2017-03-28
- 1.1.1 — 2015-05-07
- 1.1.0 — 2014-10-03
- 1.0.0 — 2014-08-13
- 0.1.3 — 2014-03-26
- 0.1.2 — 2014-01-01
- 0.1.1 — 2013-12-31
- 0.1.0 — 2013-12-31

## README

# tempfile

> Get a random temporary file path

**Checkout out [`tempy`](https://github.com/sindresorhus/tempy) which is a better take on this module.**

## Install

```sh
npm install tempfile
```

## Usage

```js
import tempfile from 'tempfile';

tempfile();
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
```

## API

### tempfile(options?)

#### options

Type: `object`

##### extension

Type: `string`

A file extension to append to the path.

```js
import tempfile from 'tempfile';

tempfile();
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'

tempfile({extension: 'png'});
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
```

## Related

- [tempy](https://github.com/sindresorhus/tempy) - Get a random temporary file or directory path
- [temp-write](https://github.com/sindresorhus/temp-write) - Write string/buffer/stream to a random temp file

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