草庐IT

async-process

全部标签

node.js - Gradle "... occurred starting process ' 命令 'npm' '"在 Mac 上

我安装了带有IntelliJIdea的MacOS。我正在使用Gradle(gradle-2.4)来构建项目。我在Mac上安装了NodeJS和NPM,并且可以从shell中使用。MacBook:~user$node-vv4.2.2MacBook:~user$npm-v2.14.7运行使用NODE/NPM的Gradle任务时,它会失败并出现以下错误(在当前示例中为NPM)。*Whatwentwrong:Executionfailedfortask':module:task'.>Aproblemoccurredstartingprocess'command'npm''来自Gradle的错误堆

javascript - Node.js 异步库比较 - Q 与 Async

我用过kriskowal'sQlibrary对于一个项目(网络爬虫/人类事件模拟器),并且已经熟悉了Promise、返回和解析/拒绝它们,并且库的基本异步控制流方法和错误抛出/捕获机制已被证明是必不可少的。虽然我遇到了一些问题。我的promise.then调用和回调具有形成金字塔的不可思议的趋势。有时是出于范围界定的原因,有时是为了保证一定的事件顺序。(我想我也许可以通过重构来解决其中的一些问题,但接下来我想完全避免“回调hell”。)此外,调试非常令人沮丧。我花了很多时间console.log——寻找错误和错误的来源;在我终于找到它们之后,我会开始在那里抛出错误并使用promise.

node.js - Grunt : execute node process and watch 中的类似 Nodemon 的任务

我觉得我错过了什么。这是我想要实现的目标:有一个执行我的server.js并并行运行watch任务的grunt任务。在我看来,这正是grunt设计的任务之一,但我无法实现这种配置。除其他外,我读过这个:RunningNodeappthroughGrunt但我还是做不到。这是我的Gruntfile.js:module.exports=function(grunt){//Projectconfiguration.grunt.initConfig({watch:{scripts:{files:['*.js'],tasks:['start'],options:{nospawn:true}}}}

javascript - process.stdin 流的可读事件和数据事件有什么区别?

说我有process.stdin.setEncoding('utf8');varmyString='';两者有什么区别process.stdin.on('readable',function(){myString+=process.stdin.read();});和process.stdin.on('data',function(chunk){myString+=chunk;});如果输入字符串在标准输入结束后相同,他们会给我相同的myString每种方法的最佳做法是什么?谢谢 最佳答案 它们是两个不同的API,允许您访问相同的数据

javascript - 从命令行读取参数 - 错误 TS2304 : Cannot find name 'process'

使用TypeScript1.7.5版。我正在编写一个nodeJS程序,我想在其中读取用户传递的命令行参数(2个整数)。在原始JavaScript中一切正常,但TypeScript出现问题。当process.argv在TypeScript文件中使用,当它被编译为JavaScript时,编译器会出错,因为它无法识别“进程”变量。errorTS2304:Cannotfindname'process'我已尝试在文件顶部声明一个新的var“进程”,但这会覆盖native变量并且它不再包含参数...我想将所有代码都保留在TypeScript中,只在构建时编译为JavaScript。解决此问题的最佳

javascript - Intellij Idea 警告 - "Promise returned is ignored"与 async/await

我在Node.jsv7.3的代码中使用Express.js。在此,我创建了一个UserRouter,它将请求转发到我的UserController。我在UserController中使用async/await来执行异步调用。问题是IntelliJ给了我一个警告,说Promisereturnedfromlogin()isignored.问题是我什至没有从login()方法返回任何内容。这是代码-UserRouter.jsrouter.post('/login',function(req,res,next){userController.login(req,res);//Igetthewa

node.js - Nodejs子进程: write to stdin from an already initialised process

我正在尝试使用Node的child_process生成一个外部进程phantomjs,然后在初始化后向该进程发送信息,这可能吗?我有以下代码:varspawn=require('child_process').spawn,child=spawn('phantomjs');child.stdin.setEncoding='utf-8';child.stdout.pipe(process.stdout);child.stdin.write("console.log('HellofromPhantomJS')");但我在标准输出上得到的唯一信息是phantomjs控制台的初始提示。phant

javascript - 在新的 Promise() 构造函数中使用 async/await 是一种反模式吗?

我正在使用async.eachLimit函数来控制一次操作的最大数量。const{eachLimit}=require("async");functionmyFunction(){returnnewPromise(async(resolve,reject)=>{eachLimit((awaitgetAsyncArray),500,(item,callback)=>{//dootherthingsthatusenativepromises.},(error)=>{if(error)returnreject(error);//resolveherepassingthenextvalue.}

javascript - await 仅在 async 函数中有效

我在lib/helper.js中编写了这段代码:varmyfunction=asyncfunction(x,y){....return[variableA,variableB]}exports.myfunction=myfunction;然后我尝试在另一个文件中使用它:varhelper=require('./helper.js');varstart=function(a,b){....constresult=awaithelper.myfunction('test','test');}exports.start=start;我遇到了一个错误:awaitisonlyvalidinasy

javascript - 如何使用 Bluebird promise Node 的 child_process.exec 和 child_process.execFile 函数?

我正在使用Node.js下的BluebirdPromise库,非常棒!但我有一个问题:如果您查看Node的文档child_process.exec和child_process.execFile你可以看到这两个函数都返回了一个ChildProcess对象。那么推荐的方法是什么?请注意以下工作(我得到一个Promise对象):varPromise=require('bluebird');varexecAsync=Promise.promisify(require('child_process').exec);varexecFileAsync=Promise.promisify(requir