I have some code that is kinda working (the functions do what they are supposed to do), but it looks ugly and I am sure there is a better way to do this.
I need to run three functions, one after the other, if they are successful. What I have done looks like this.
Is this correct? Is there a better (I am sure) way to do this?
function1({
dosomething
}, function(err, result) {
if (err) {
callback('There was an error: ' + err);
}
else{
console.log(' function 1 done');
function2({
somethingelse
}, function(err, result) {
if (err) {
callback('There was an error on function2: ' + err);
}
else{
console.log('function2 ok');
function3({
blah
function(err, result) {
console.log(result);
console.log(err);
callback(err, response)
});
}
});
}
}
);