mongoose_fixtures.js
function loadDir(dir, db, callback) {
    callback = callback || function() {};
    
    //Get the absolute dir path if a relative path was given
    if (dir.substr(0, 1) !== '/') {
        var parentPath = module.parent.filename.split('/');
        parentPath.pop();
        dir = parentPath.join('/') + '/' + dir;
    }
    
    //Load each file in directory
    fs.readdir(dir, function(err, files){
        if (err) return callback(err);
        
        var iterator = function(file, next){
            loadFile(dir + '/' + file, db, next);
        };
        async.forEach(files, iterator, callback);
    });
}
function loadDir(dir, db, callback) {
    callback = callback || function() {};
    
    //Get the absolute dir path if a relative path was given
    if (dir.substr(0, 1) !== '/') {
        var parentPath = module.parent.filename.split('/');
        parentPath.pop();
        dir = parentPath.join('/') + '/' + dir;
    }
    
    //Load each file in directory
    fs.readdir(dir, function(err, files){
        if (err) return callback(err);
        
        var iterator = function(file, next){
            loadFile(dir + '/' + file, db, next);
        };
        async.forEach(files, iterator, callback);
    });
}
function loadDir ( dir , db , callback ) { callback = callback || function ( ) { } ; //Get the absolute dir path if a relative path was given if ( dir . substr ( 0 , 1 ) !== '/' ) { var parentPath = module . parent . filename . split ( '/' ) ; parentPath . pop ( ) ; dir = parentPath . join ( '/' ) + '/' + dir ; } //Load each file in directory fs . readdir ( dir , function ( err , files ) { if ( err ) return callback ( err ) ; var iterator = function ( file , next ) { loadFile ( dir + '/' + file , db , next ) ; } ; async . forEach ( files , iterator , callback ) ; } ) ; }
Loads fixtures from all files in a directory

TODO: Add callback option

@param {String}      The directory path to load e.g. 'data/fixtures' or '../data'
@param {Connection}  The mongoose connection to use
@param {Function}    Callback
Loads fixtures from all files in a directory