I am trying to get folder size of a directory in Node.js, but it runs the last line as Undefined first and then log the size in the callback function. It works if I put the last line of the code in a setTimeout function with a few seconds delay...
const getSize = require('get-folder-size');
let folderSize;
getSize(folder, (err, size) => {
folderSize = size;
console.log(size);
});
console.log(folderSize);
Is there a way to get the result from the callback first and then get the result of the last line of the code?
Also, is there a sleep() to pause between codes like wscript.sleep(sec) in VBScript? I googled but couldn't find what I want.