Answers

Question and Answer:

  Home  Node.js

⟩ Are you sure node.js execute system command synchronously?

There's an excellent module for flow control in node.js called asyncblock. If wrapping the code in a function is OK for your case, the following sample may be considered:

var asyncblock = require('asyncblock');

var exec = require('child_process').exec;

asyncblock(function (flow) {

exec('node -v', flow.add());

result = flow.wait();

console.log(result); // There'll be trailing n in the output

// Some other jobs

console.log('More results like if it were sync...');

});

 143 views

More Questions for you: