Skip to content

Instantly share code, notes, and snippets.

@d0whc3r
Created May 6, 2018 10:41
Show Gist options
  • Save d0whc3r/219c6f46b03d73b35c1b74dc31349092 to your computer and use it in GitHub Desktop.
Save d0whc3r/219c6f46b03d73b35c1b74dc31349092 to your computer and use it in GitHub Desktop.
simple recursive mkdir
const path = require('path');
const fs = require('fs');
function mkdirp(targetDir) {
const sep = path.sep;
const initDir = path.isAbsolute(targetDir) ? sep : '';
targetDir.split(sep).reduce((parentDir, childDir) => {
const curDir = path.resolve(parentDir, childDir);
if (!fs.existsSync(curDir)) {
fs.mkdirSync(curDir);
}
return curDir;
}, initDir);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment