使用async中断节点脚本

break node script with async

本文关键字:脚本 节点 中断 async 使用      更新时间:2023-09-26

我正在运行npm install命令在Node上的模块列表,并有一个关于async的错误

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对象上调用适当的方法:
return async.methodThatYouWantToCall();