Skip to content

Instantly share code, notes, and snippets.

@draobrehtom
Created September 15, 2019 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draobrehtom/5deaf346955257f88b2c8b07f61689ae to your computer and use it in GitHub Desktop.
Save draobrehtom/5deaf346955257f88b2c8b07f61689ae to your computer and use it in GitHub Desktop.
Two different approaches to List files in NodeJS
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