Created
September 15, 2019 16:32
-
-
Save draobrehtom/5deaf346955257f88b2c8b07f61689ae to your computer and use it in GitHub Desktop.
Two different approaches to List files in NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let start = new Date(); | |
require('fs').readdir(require('path').join(__dirname), (err, files) => { | |
if (! err) { | |
files.forEach(function (file) { | |
require('./' + file); | |
}); | |
} | |
}); | |
console.log(new Date() - start + 'ms'); // 1 ' ms' | |
start = new Date(); | |
require('util').promisify(require('child_process').exec)('dir').then((out, err) => { | |
}); | |
console.log(new Date() - start + 'ms'); // 12 ' ms' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment