Are you sure node.js execute system command synchronously?
Submitted by: AdministratorThere'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...');
});
Submitted by: Administrator
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...');
});
Submitted by: Administrator
Read Online Node.js Job Interview Questions And Answers
Top Node.js Questions
☺ | Explain Node.js Architecture? |
☺ | How to extract POST data in node.js? |
☺ | What is Node.js? |
☺ | Do you know how to debug node.js applications? |
☺ | Do you know how to get POST query in express node.js? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |