Skip to content

Instantly share code, notes, and snippets.

@nathabonfim59
Created July 21, 2017 01:30
Show Gist options
  • Save nathabonfim59/58ffbad0941779d6cd3c83d6e64531d1 to your computer and use it in GitHub Desktop.
Save nathabonfim59/58ffbad0941779d6cd3c83d6e64531d1 to your computer and use it in GitHub Desktop.
FullStackAcademy - aula 1 - exercício 3
const fs = require('fs')
const path = './'
/**
* Lê um diretório e retorna em array com os nomes de arquivos e pastas encontrados nele
* @param {string} path Diretório a ser analisado
*/
const readdirPromise = function(path) {
return new Promise((resolve, reject) =>
fs.readdir(path, (err, arquivos) => {
if (err) {
reject(err)
} else {
resolve(arquivos)
}
})
)}
readdirPromise(path).then((files)=> console.log(files))
@tuliofaria
Copy link

Certinho.

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