I have created a function to compress files to tar archive in a directory using tar module but I can't execute it with multiple functions through iteration because of its asynchronous behavior. How can I sync this function?
I've added sync: true to the options as it did on the documentation but it won't work
let fullPath = path.join(dir, file);
if (fs.lstatSync(fullPath).isDirectory()) {
tar
.c({
gzip: true,
file: path.resolve(
archivePath,
file + " - " + date.getTime() + ".tar.gz"
), //compressed file name
C: fullPath
},
["."]
)
.then(() => {
console.log({
status: 0,
message: "compressed - " + file
});
});
}