Sunday, 23 April 2017

Issues with reading req undefined inside some functions

I get user query information when use req.user at first time but in second inside function I got cannot read property user of null.

 router.post("/orders", function (req, res) {
        console.log(req.user);//here I can see user info!
        orders.count({
            customerInfo: req.user//here I can get user info!
        }, function (req, count) {
            if (count > 0) {
                console.log(count);
                orders.findOne({
                    customerInfo: req.user//here:cannot read property user of null
                }, function (err, orders) {
                    products.findOne({
                        _id: req.body.id
                    }, function (err, products) {
                        if (err) {
                            console.log(err);
                        } else {
                            orders.productInfo.push(products);
                            orders.save(function (err, data) {
                                if (err) {
                                    console.log(err);
                                } else {
                                    console.log(data);
                                }
                            });
                        }
                    });
                });
            }



via milad fahimi

No comments:

Post a Comment