# select-random-file

> Selects a random file from a directory

Latest version **1.2.4** (published 2022-12-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install select-random-file
pnpm add select-random-file
yarn add select-random-file
bun add select-random-file
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.4 |
| Published | 2022-12-10 |
| First published | 2017-02-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Jakob Fix |
| Maintainers | jfix |
| Keywords | random, file, select, directory |

## Links

- npm: https://www.npmjs.com/package/select-random-file
- Repository: https://github.com/jfix/npm-random-file
- Homepage: https://github.com/jfix/npm-random-file#readme
- Issues: https://github.com/jfix/npm-random-file/issues
- npm.io page: https://npm.io/package/select-random-file

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.2.4 (latest) — 2022-12-10
- 1.2.2 — 2022-11-12
- 1.2.1 — 2022-03-29
- 1.2.0 — 2021-04-15
- 1.1.0 — 2017-02-25
- 1.0.0 — 2017-02-25

## README

select-random-file
==================

[![Build status](https://github.com/jfix/npm-random-file/actions/workflows/test.yml/badge.svg)](https://github.com/jfix/npm-random-file/actions)

Select a random file from a provided directory:

```
const randomFile = require('select-random-file')

const dir = '/tmp/whatever'
randomFile(dir, (err, file) => {
  console.log(`The random file is: ${file}.`)
})
```

There are a couple of things that could be added:

* filter files by an extension
* recursively traverse a deeper directory structure

Acknowledgements
----------------

Discussion on Stack Overflow was very useful: http://stackoverflow.com/questions/42425887/how-to-use-an-async-function-as-compare-function-of-array-filter

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