lib/fileSystem.js
function mkdirRecursive(directoryPath, callback) {
  directoryPath = path.resolve(directoryPath);

  // Try to create directory
  fs.mkdir(directoryPath, function(error) {

    if (error && error.code === 'EEXIST') {

      // Can't create directory it already exists
      // It may have been created by another loop
      callback();

    } else if (error && error.code === 'ENOENT') {

      // Can't create directory, parent directory does not exist

      // Create parent directory
      mkdirRecursive(path.dirname(directoryPath), function(error) {
        if (!error) {

          // Now that parent directory is created, create requested directory
          fs.mkdir(directoryPath, function(error) {
            if (error && error.code === 'EEXIST') {

              // Can't create directory it already exists
              // It may have been created by another loop
              callback();

            } else
              callback(error);
          });

        } else
          callback(error);
      });
    } else
      callback(error);
  });
}
function mkdirRecursive(directoryPath, callback) {
  directoryPath = path.resolve(directoryPath);

  // Try to create directory
  fs.mkdir(directoryPath, function(error) {

    if (error && error.code === 'EEXIST') {

      // Can't create directory it already exists
      // It may have been created by another loop
      callback();

    } else if (error && error.code === 'ENOENT') {

      // Can't create directory, parent directory does not exist

      // Create parent directory
      mkdirRecursive(path.dirname(directoryPath), function(error) {
        if (!error) {

          // Now that parent directory is created, create requested directory
          fs.mkdir(directoryPath, function(error) {
            if (error && error.code === 'EEXIST') {

              // Can't create directory it already exists
              // It may have been created by another loop
              callback();

            } else
              callback(error);
          });

        } else
          callback(error);
      });
    } else
      callback(error);
  });
}
function mkdirRecursive ( directoryPath , callback ) { directoryPath = path . resolve ( directoryPath ) ; // Try to create directory fs . mkdir ( directoryPath , function ( error ) { if ( error && error . code === 'EEXIST' ) { // Can't create directory it already exists // It may have been created by another loop callback ( ) ; } else if ( error && error . code === 'ENOENT' ) { // Can't create directory, parent directory does not exist // Create parent directory mkdirRecursive ( path . dirname ( directoryPath ) , function ( error ) { if ( ! error ) { // Now that parent directory is created, create requested directory fs . mkdir ( directoryPath , function ( error ) { if ( error && error . code === 'EEXIST' ) { // Can't create directory it already exists // It may have been created by another loop callback ( ) ; } else callback ( error ) ; } ) ; } else callback ( error ) ; } ) ; } else callback ( error ) ; } ) ; }
Creates a directory recursively and asynchronously.

If parent directories do not exist, they will be automatically created.

@method mkdirRecursive
@private
@static
@async
@param {String} directoryPath The directory system path to create
@param {Function} callback The function to call when done
- **Error** The error if an error occurred, null otherwise
Creates a directory recursively and asynchronously .