Skip to content

Instantly share code, notes, and snippets.

@boboidream
Created March 21, 2017 02:30
Show Gist options
  • Save boboidream/bfdbf2946607a1708c8f6e85737e558e to your computer and use it in GitHub Desktop.
Save boboidream/bfdbf2946607a1708c8f6e85737e558e to your computer and use it in GitHub Desktop.
// Create dir recursively if it does not exist!
const targetDir = 'path/to/dir';
targetDir.split('/').forEach((dir, index, splits) => {
const parent = splits.slice(0, index).join('/');
const dirPath = path.resolve(parent, dir);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment