Node.js Question:

Download Job Interview Questions and Answers PDF

Are you sure node.js execute system command synchronously?

Node.js Interview Question
Node.js Interview Question

Answer:

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...');
});

Download Node.js Interview Questions And Answers PDF

Previous QuestionNext Question
Tell me how to make an HTTP POST request in node.js?Tell me how to use underscore.js as a template engine?