mardi 16 mars 2021

Load random file from directory

So i'm building a game and i want to choose a random file from a directory as a map. I found this old topic which gave the answer

const randomFile = require('random-file')

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

but it seems that fs is no longer in use, but fs.realpath




Aucun commentaire:

Enregistrer un commentaire