index.js
function rmdirRecursive(root, chunks, callback) {

  var chunk = chunks.pop();
  if (!chunk) {
    return callback(null);
  }
  var pathname = path.join(root, '..'); // backtrack

  return fs.exists(root, function(exists) {

    if (exists === false) { // already done
      return rmdirRecursive(root, chunks, callback);
    }
    return fs.rmdir(root, function(err) {

      if (err) {
        return callback(err);
      }
      return rmdirRecursive(pathname, chunks, callback); // let's magic
    });
  });
}
function rmdirRecursive(root, chunks, callback) {

  var chunk = chunks.pop();
  if (!chunk) {
    return callback(null);
  }
  var pathname = path.join(root, '..'); // backtrack

  return fs.exists(root, function(exists) {

    if (exists === false) { // already done
      return rmdirRecursive(root, chunks, callback);
    }
    return fs.rmdir(root, function(err) {

      if (err) {
        return callback(err);
      }
      return rmdirRecursive(pathname, chunks, callback); // let's magic
    });
  });
}
function rmdirRecursive ( root , chunks , callback ) { var chunk = chunks . pop ( ) ; if ( ! chunk ) { return callback ( null ) ; } var pathname = path . join ( root , '..' ) ; // backtrack return fs . exists ( root , function ( exists ) { if ( exists === false ) { // already done return rmdirRecursive ( root , chunks , callback ) ; } return fs . rmdir ( root , function ( err ) { if ( err ) { return callback ( err ) ; } return rmdirRecursive ( pathname , chunks , callback ) ; // let's magic } ) ; } ) ; }
remove directory recursively

@function rmdirRecursive
@param {String} root - absolute root where take chunks
@param {Array} chunks - directories chunks
@param {Function} callback - next callback
remove directory recursively