Monday, 29 May 2017

I have created an API in node js in which I am pushing some data. I want as data update in database, it should reflect in UI

Right now I am calling API in every time 3 seconds to retrieve that data using $timeout(Angular Js). I want some better solution than that. I read about node io but I am not able to make it work. Please give a better solution with example.

//Node js Code
router.put('/question/addComments',function(req,res){
    Question.findOne({_id:req.body.questionID},function(err,question){
        if(err){
            return res.send(err);
        }
        else{
                question.commentsCount = question.commentsCount + 1;
            question.comments.push(req.body.comment);
            question.save(function(err, question){
                if(err){
                    res.send(err);
                }
                res.json(question);
            });
        }
    });
});


via Ikshit Mathur

No comments:

Post a Comment