Wondering what’s next for npm?Check out our public roadmap! »

select-random-file

1.1.0 • Public • Published

select-random-file

Build Status

Select a random file from a provided directory:

const randomFile = require('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

Install

npm i select-random-file

DownloadsWeekly Downloads

9

Version

1.1.0

License

ISC

Last publish

Collaborators

  • avatar