How to execute a function and wait for a result to save the data:
I have
if (!_.isUndefined(image)){
upload(image).then(function(response) {
if (!response.success)
return res.status(202).send(upload);
image = response.image;
});
}
dataProfile.save(function(err, data) {
return res
.send({
success: true,
data: data
});
});
but when I run, when I save the value of image it takes it undefined or it takes a previous value because it has not finished executing the function. How would you expect the result of the function and save it?