src/server/util/ensureDir.js
function ensureDir(dir, mode, callback) {
    var deferred = Q.defer();

    if (mode && typeof mode === 'function') {
        callback = mode;
        mode = null;
    }

    mode = mode || parseInt('0777', 8) & (~process.umask());


    _ensureDir(dir, mode, function (err) {
        if (err) {
            deferred.reject(err);
        } else {
            deferred.resolve();
        }
    });

    return deferred.promise.nodeify(callback);
}
function ensureDir(dir, mode, callback) {
    var deferred = Q.defer();

    if (mode && typeof mode === 'function') {
        callback = mode;
        mode = null;
    }

    mode = mode || parseInt('0777', 8) & (~process.umask());


    _ensureDir(dir, mode, function (err) {
        if (err) {
            deferred.reject(err);
        } else {
            deferred.resolve();
        }
    });

    return deferred.promise.nodeify(callback);
}
function ensureDir ( dir , mode , callback ) { var deferred = Q . defer ( ) ; if ( mode && typeof mode === 'function' ) { callback = mode ; mode = null ; } mode = mode || parseInt ( '0777' , 8 ) & ( ~ process . umask ( ) ) ; _ensureDir ( dir , mode , function ( err ) { if ( err ) { deferred . reject ( err ) ; } else { deferred . resolve ( ) ; } } ) ; return deferred . promise . nodeify ( callback ) ; }
ensure a directory exists, create it recursively if not.

@param dir The directory you want to ensure it exists
@param mode Refer to fs.mkdir()
@param callback
ensure a directory exists create it recursively if not .