I'm new to node.js (and also backend) for only a week, and now I'm trying to do a simple registration. I found that it's really hard to reduce complexity because pretty much every callback is error-first. Is there any way to reduce this? Here's my code, I found it seems impossible to avoid all of those if-elsesconst User = require('../../models/user')const ERROR_MESSAGES = require('../../models/constant').ERROR_MESSAGESconst RESPONSE_STATUS = require('../../models/constant').RESPONSE_STATUSconst helper = require('../../helpers/helper')const validator = require('validator')module.exports.register = function(req, res) {    const email = req.body.email    const password = req.body.password    const errors = []    // input validation    if (!email || email.trim().length == 0) {        errors.push(ERROR_MESSAGES.EMPTY.EMAIL)    } else if (!validator.isEmail(email)) {        errors.push(ERROR_MESSAGES.INVALID.EMAIL)    }    if (!password) {        errors.push(ERROR_MESSAGES.EMPTY.PASSWORD)    }    if (errors.length > 0) {        return res.json(helper.generateResponse(errors, null, RESPONSE_STATUS.REQUEST_DENIED))    } else {        User.findOne({email: email}, function(err, user){            if (err) {                 res.json(helper.generateResponse([ERROR_MESSAGES.UNKNOW], null, RESPONSE_STATUS.REQUEST_DENIED))             } else if (user) {                res.json(helper.generateResponse([ERROR_MESSAGES.DUPLICATE.EMAIL], null, RESPONSE_STATUS.REQUEST_DENIED))            } else {                var user = new User()                user.email = email                user.password = user.generateHash(password)                var errorValidation = user.validateSync();                if (errorValidation) {                    // input validation                    errors = helper.getMongooseValidationErrors(errorValidation.errors)                    res.json(helper.generateResponse(errors, null, RESPONSE_STATUS.REQUEST_DENIED))                } else {                    user.save(function(error, newUser) {                        if (error) {                             res.json(helper.generateResponse([error], null, RESPONSE_STATUS.REQUEST_DENIED))                        } else {                            res.json(helper.generateResponse(errors, newUser, RESPONSE_STATUS.SUCCESS))                        }                    })                }            }        })    }}
Node js and Mongoose reduce complexity
node.js;mongoose