# unique-filename

> Generate a unique filename for use in temporary directories or caches.

Latest version **6.0.0** (published 2026-05-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install unique-filename
pnpm add unique-filename
yarn add unique-filename
bun add unique-filename
```

## Health

**Score 50/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance.

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

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2026-05-15 |
| First published | 2015-05-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ^22.22.2 \|\| ^24.15.0 \|\| >=26.0.0 |
| Dependencies | 1 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 45 |
| Author | GitHub Inc. |
| Maintainers | saquibkhan, npm-cli-ops, reggi, owlstronaut |

## Links

- npm: https://www.npmjs.com/package/unique-filename
- Repository: https://github.com/npm/unique-filename
- Homepage: https://github.com/iarna/unique-filename
- Issues: https://github.com/iarna/unique-filename/issues
- npm.io page: https://npm.io/package/unique-filename

## Dependencies (1)

- [unique-slug](https://npm.io/package/unique-slug.md) ^7.0.0

## Recent versions

- 6.0.0 (latest) — 2026-05-15
- 5.0.0 — 2025-10-22
- 4.0.0 — 2024-09-26
- 3.0.0 — 2022-10-14
- 2.0.1 — 2022-08-25
- 2.0.0 — 2022-08-22
- 1.1.1 — 2018-09-20
- 1.1.0 — 2015-12-03
- 1.0.0 — 2015-05-07

## README

unique-filename
===============

Generate a unique filename for use in temporary directories or caches.

```js
const uniqueFilename = require('unique-filename')

// returns something like: '/tmp/c5b28f47'
const randomTmpfile = uniqueFilename(os.tmpdir())

// returns something like: '/tmp/my-test-51a7b48d'
const randomPrefixedTmpfile = uniqueFilename(os.tmpdir(), 'my-test')

// returns something like: '/my-tmp-dir/testing-7ddd44c0'
const uniqueTmpfile = uniqueFilename('/my-tmp-dir', 'testing', '/my/thing/to/uniq/on')
```

### uniqueFilename(*dir*, *fileprefix*, *uniqstr*) → String

Returns the full path of a unique filename that looks like:
`dir/prefix-7ddd44c0`
or `dir/7ddd44c0`

*dir* – The path you want the filename in. `os.tmpdir()` is a good choice for this.

*fileprefix* – A string to append prior to the unique part of the filename.
The parameter is required if *uniqstr* is also passed in but is otherwise
optional and can be `undefined`/`null`/`''`. If present and not empty
then this string plus a hyphen are prepended to the unique part.

*uniqstr* – Optional, if not passed the unique part of the resulting
filename will be random.  If passed in it will be generated from this string
in a reproducible way.

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