Q:

Having issue in updating the data in Node js

router.put('/edit:/id',(req,res)=>{

Post.findOne({_id: req.params.id}).then(post=>{
    if(req.body.allowComments)
         {
            allowComments = true;
         }
        else
            {
                allowComments = false;
            }

        post.title = req.body.title;
        post.status = req.body.status;
        post.allowComments = allowComments;
        post.body= req.body.body;

        post.save().then(updatedPost=>
        {
            res.redirect('/admin/posts');

        });

});

});

Showing error don't know why please help
I want to update the record or make changes to the previous data.
I'm using nodejs deletion and all are working fine but updation are creating issue

A:

you are using wrong syntax router.put('/edit/:id',(req,res)=>
this is the correct way
router.put('/edit/:id',(req,res)=>{

Post.findOne({_id: req.params.id}).then(post=>{
    if(req.body.allowComments)
         {
            allowComments = true;
         }
        else
            {
                allowComments = false;
            }

        post.title = req.body.title;
        post.status = req.body.status;
        post.allowComments = allowComments;
        post.body= req.body.body;

        post.save().then(updatedPost=>
        {
            res.redirect('/admin/posts');

        });

});

});

