Skip to content

Instantly share code, notes, and snippets.

@euforic
Created November 21, 2013 04: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 euforic/7576123 to your computer and use it in GitHub Desktop.
Save euforic/7576123 to your computer and use it in GitHub Desktop.
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
Copy link
Author

euforic commented Nov 21, 2013

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