Create a gist now

Instantly share code, notes, and snippets.

function mkdirP (p, fn, made) {
if (!made) made = null;
var cb = fn || function () {};
p = path.resolve(p);
fs.mkdir(p, function (err) {
if (!err) return cb(null, made || p);
if (err.code != 'ENOENT') return err;
mkdirP(path.dirname(p), mode, function (err, made) {
if (err) cb(err, made);
return mkdirP(p, cb, made);
});
});
}
/**
* usage
*/
mkdirP('/Users/euforic/test_cases/mkdirP', function(){
console.log(fs.existsSync('/Users/euforic/test_cases/mkdirP'));
});
@euforic
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment