Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
const fs = require('fs');
const filelist = [
'data/all1.txt',
'data/all2.txt',
'data/all3.txt',
'data/all4.txt',
];
const filelength = async filename => new Promise((resolve, reject) => {
fs.readFile(filename, (err, data) => {
if (err) {
reject(err);
}
else {
resolve({filename, length:data.length});
}
});
});
const main = async function () {
let contains = await Promise.all(filelist.map(filelength));
console.log(contains);
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment