用异步中断节点脚本

break node script with async

我正在 运行 npm install 命令获取 Node 上的模块列表,但有一个关于异步的错误

TypeError: undefined is not a function

有什么问题?

var fs = require( "fs" ),
    path = require( "path" ),
    child_process = require( "child_process"),
    async = require( "async"),
    modulesPath = "../modules/";

var dirs = fs.readdirSync( modulesPath )
    .filter( function( dir ) {
        return fs.statSync( path.join( modulesPath, dir )).isDirectory();
    });

var install = function() {
    if ( dirs.length === 0 ) {
        return;
    }

    var dir = dirs.shift();
    console.log( "installing dependencies for : '" + dir + "'" );

    child_process.exec( "npm prune --production | npm install", {
        cwd: modulesPath + dir
    }, install );


  };

install();

问题是您将 async 变量视为引用了一个函数,而实际上它引用了一个对象:

return this.async();

您应该更改上面的行,以便在 async 对象上调用 appropriate method

return async.methodThatYouWantToCall();