如何在Node.js中发布发布请求?

当前发帖要求:

app.post('/rImage', rawBody, function (req, res) { // ---- check here, if this process is running ? ---- var data = req.rawBody; var escapedData = data.replace(/([<>|&^])/g, "\^$1"); // Windows CMD escaping exec('cscript /nologo C:/PS/Automation/render.vbs C:/PS/Automation/image.jsx"'+escapedData + '"', function (error, stdout, stderr) { console.log('stdout: ' + escapedData); if(error !== null) { console.log('exec error: ' + error); } res.send(stdout); //request finished }); }); 

我怎么能实现一个队列系统,以便下一个请求在最后一个请求完成时触发?

非常感谢!

可能有这样的库。 但是,你可以像这样破解它:

 var queue = []; var active = false; var check = function() { if (!active && queue.length > 0) { var f = queue.shift(); f(); } } app.post("..", body, function(req, res) { queue.push(function() { active = true; exec("yourprogram arg1 arg2..", function() { // this is the async callback active = false; check(); }); }); check(); }); 

这是一个小提琴,显示function: https : //jsfiddle.net/fc15afw5/1/