Skip to content

Instantly share code, notes, and snippets.

@huang-x-h
Last active August 9, 2020 00:41
Show Gist options
  • Save huang-x-h/b48e1ea3cd4e1561ed43 to your computer and use it in GitHub Desktop.
Save huang-x-h/b48e1ea3cd4e1561ed43 to your computer and use it in GitHub Desktop.
mkdir recursive
// path需以斜杠结尾
var fs = require('fs'),
path = 'base/base/base/';
path.split('/').reduce(function(prev, next) {
if (!fs.existsSync(prev))
fs.mkdirSync(prev);
return prev + '/' + next;
});
@swyxio
Copy link

swyxio commented Aug 9, 2020

(for future pple who find this) as of node 10 you can use fs.mkdirSync(path, {recursive: true})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment