I am currently using shell.js's mkdir -p in my node.js code which is synchronous. The '-p' is used in shell.mkdir to create a directory with a full path, something that fs.mkdir
cannot do.
if(fs.existsSync(archivePath + "\\" + site + "\\" + year)){ // check if site folder exists
console.log(archivePath + "\\" + site + "\\" + year + " exists");
}
else {
console.log(archivePath + "\\" + site + "\\" + year + " does not exist... creating full path now");
shell.mkdir('-p' , archivePath + "\\" + site + "\\" + year + "\\" + missionID);
}
If anyone knows of a way to get the asynchronous nature of fs.mkdir
, and the recursive nature of shell.mkdir('-p', absolutePath)
, in one fell swoop please let me know.
So I figured out that I could just use mkdirp to do a directory with a full path via a promise.
See full documentation here