select-random-file
TypeScript icon, indicating that this package has built-in type declarations

1.2.4 • Public • Published

select-random-file

Build status

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

Package Sidebar

Install

npm i select-random-file

Weekly Downloads

66

Version

1.2.4

License

ISC

Unpacked Size

6.08 kB

Total Files

8

Last publish

Collaborators

  • jfix