I have a MEAN Stack app in which I have been using mongoose routes to update my data. Some of those routes have a lot of back and forth in terms of updating data across multiple users and collections. So I used the standard mongoose callbacks to handle them. It all worked perfectly but it turned into Callback Hell! So I turned towards using promises.My Question:Although my new code is still quite long but I think its much easier to manage and maintain. What do you think about my move from callback to promises? Have I implemented it right? Is there anything else I can do to improve it?Old CallBack Code: (as you can see its callback hell and very confusing)app.post('/bios/approve', isLoggedIn, function(req, res) {if (req.user.accessLevel.indexOf('Bio Officer UK') > -1) {Bio.findOneAndUpdate({userID: req.body.userID, bioForSector: req.body.bioForSector }, {    background: req.body.background,    experience: req.body.experience,    skills: req.body.skills,    otherSkills: req.body.otherSkills,    bioStatus: req.body.bioStatus,    approvalStage: Bio Designer}, function(err, editedBio) {    if (err) {console.log(Error while editing Pending Bio is  + err);}     else if (editedBio) {        User.findOneAndUpdate({            accessLevel: Bio Designer        }, {            $push: {                biosPending: editedBio._id            }        }, function(err, user) {            if (err) {                console.log(The error while finding lineManager is  + err);            } else if (user) {                User.findOneAndUpdate({                    accessLevel: Bio Officer UK                }, {                    $pull: {                        biosPending: editedBio._id                    }                }, function(err, bioOfficer) {                    if (err) {                        console.log(The error while finding lineManager is  + err);                    } else if (!bioOfficer) {                        req.flash('addBioMessage', 'An error occured while trying to approve this bio, please contact the system admin and provide them this error code: ER2503J');                        return (res.json({                            message: An error occured while trying to approve this bio, please contact the system admin and provide them this error code: ER2503J                        }));                    } else if (bioOfficer) {                        var data = {                            from: '',                            to: user.email,                            subject: 'KB - Bio Pending',                            text: 'Hi ' + user.firstName + '\n This email is to inform you that a user has added their bio to the knowledge Base \n\n' +                                'Please login to the system & view and approve the bio so it can be finalised.\n\n' +                                'Thank you!\n'                        };                        mailgun.messages().send(data, function(error, body) {                            console.log(body);                            console.log(sending bio added email to bio officer);                            req.flash('successMessage', 'Bio approved & moved on to the next stage to the Bio Designer.');                            return (res.json({                                message: Bio approved & moved on to the next stage.                            }));                        });                    }                });            } else if (!user) {                req.flash('addBioMessage', 'An error occured while trying to approve this bio, please contact the system admin and provide them this error code: ER2503I');                return (res.json({                    message: An error occured while trying to approve this bio, please contact the system admin and provide them this error code: ER2503I                }));            }        });    }}); }New Promises Code:if(req.user.accessLevel.indexOf('Bio Officer UK') > -1){            return _findBio(req.body)                .then(function(bio) {                    return _findBioDesigner(bio._id)                })                .then(function(designer){                    _sendEmail(designer, req.body);                    return _findBio(req.body)                })                .then(function(bio){                    return _findBioOfficer(bio._id)                })                .then(function(officer){                    req.flash('successMessage', 'Bio approved & moved on to the next stage to the Bio Designer.');                    return res.status(200).json()                 })                .catch(function(err){                    if(err)                    req.flash('addBioMessage', 'An error occured while trying to approve this bio, please contact the system admin and provide them this error code: ER2503I');                    return res.status(500).json(null)                })        }Functions returning Promises:// Find and Updatefunction _findBio(bio){    return Bio.findOneAndUpdate({userID: bio.userID, bioForSector: bio.bioForSector},{                background: bio.background,                experience: bio.experience,                skills: bio.skills,                otherSkills: bio.otherSkills,                bioStatus: bio.bioStatus,                approvalStage: Bio Designer            }).exec()};// Find and Updatefunction _findBioDesigner(bio){    return User.findOneAndUpdate({accessLevel: Bio Designer},{$push:{biosPending: bio}}).exec()};// Find and Updatefunction _findBioOfficer(bio){    return User.findOneAndUpdate({accessLevel: Bio Officer UK},{$pull:{biosPending: bio}}).exec()}// Inform User/Send Emailfunction _sendEmail(designer, bio){    var data = {    from: '',                    to: designer.email,                    subject: 'KB - Bio Pending',                    text: 'Hi ' + designer.firstName + '\n This email is to inform you that ' + bio.firstName + ' ' + bio.lastName + ' has added their bio to the knowledge Base \n\n' +                                'Please login to the System & view and approve the bio so it can be finalised.\n\n' +                                'Thank you!\n'                    };                    mailgun.messages().send(data, function(error, body) {                    });}
From Callbacks to Promises - MEAN Stack
javascript;performance;node.js;promise;callback