I have multiple functions inside my route and want to execute them in order for eg the control should only move to the next function if the previous function has been successfully executed. For eg refer the below code, I wish to execute task1 first followed by task 2 and so on. Setting a timeout or await doesn't seem to be an efficient way, do I need to add async functions or something similar?
Code.js
var task1 = cp.exec('docker images', function (error, stdout, stderr) {
console.log('Version: ' +version);
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
var task2 = cp.exec('docker pull mongo:'+version, function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
var task3 = cp.exec('docker run -d -p '+port2+':27017 -v '+volumeLoc+' --name '+containerName+' mongo:'+version, function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
var task4 = cp.exec('docker ps | grep mongo', function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});