Skip to content

Instantly share code, notes, and snippets.

@wescleymatos
Created July 20, 2017 01:35
Show Gist options
  • Save wescleymatos/e554c085fc05a308c33a20c8d0cb3253 to your computer and use it in GitHub Desktop.
Save wescleymatos/e554c085fc05a308c33a20c8d0cb3253 to your computer and use it in GitHub Desktop.
const fs = require('fs')
const path = './'
function readdirPromise(path) {
return new Promise((resolve, reject) => {
fs.readdir(path, (err, files) => {
if (err) {
reject(err);
} else {
resolve(files);
}
})
})
}
async function listaItensDiretorio(path) {
try {
const itens = await readdirPromise(path);
console.log(itens);
} catch(e) {
console.log(e);
}
}
listaItensDiretorio(path);
@tuliofaria
Copy link

Certinho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment