Skip to content

Instantly share code, notes, and snippets.

@mlrawlings
Last active December 14, 2015 02:59
Show Gist options
  • Save mlrawlings/5017523 to your computer and use it in GitHub Desktop.
Save mlrawlings/5017523 to your computer and use it in GitHub Desktop.
Ensure that a directory exists (and create it if it doesn't)
function ensureDirectoryExists( path, fn ) {
fs.exists( path, function( exists ) {
if( exists ) {
fn();
} else {
var parent = path.replace( /(\/|\\)[^\/\\]+$/, '' );
ensureDirectoryExists( parent, function() {
fs.mkdir( path, fn );
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment