I have this function getSize() (from npm module: get-folder-size) that's calculating the total size of all files in a folder (directory).
const getSize = require('get-folder-size')
let folders = ["C:\\test folder", "C:\\test folder 2\\sub folder"]
funciton totalFilesizeOfAllFolders () {
let totalSizeOfAllFolders = 0
this.folders.forEach(folder => {
getSize(folder, (err, size) => {
if (err) { throw err }
// ADD UP THE "SIZE" TO THE TOTAL SOMEHOW
// Just doing the following returns 0: totalSizeOfAllFolders += size
})
})
return totalSizeOfAllFolders
}
Question
How do I loop through the array folders properly and add up the calculated sizes of all the folders in the array? I'm not sure how to return the size out of the function
getSize()function is asynchronous.