Skip to content

Instantly share code, notes, and snippets.

@boboidream
Created March 21, 2017 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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