i'm a little bit confused how i'm gonna approach my problem and whats the best practise is.
On my node server i have this post function:
router.post('/addUser', (req, res, next) => {
const newUser = new User({
userName: req.body.userName
userPicture: req.body.profilePicture
personLookALike: -> functionThatReturnsAObjectAsynchronously() <-
...
})
}
The problem is, i want to save the post so i normally would have this later in the code:
newUser.save()
But newUser.save() gets executed first before the Object is fully finished(the "personLookALike" property is missing)
I know i could wrap this all with a promise and then put the save proces in a then() block but i have more of these asynchronous function in the object creation.
What is the best practise for my approach? Thank you!