title: Express Router CRUD Update and Delete data
body: <p>I have issues to implement CRUD to my webapp, The data are stored in the mongoDB at the cloud successfully using a FORM,also managed to display the data for the user. But my issue is to update the inserted data also to delete them.
  Please take a look my codes. When I click on Update / Delete links I get Cannot GET /delete/ or Cannot GET /Update/.
  I would appreciate If anyone can help me out.</p>
  
  <blockquote>
    <p>server.js</p>
  </blockquote>
  
  <pre><code>    app.get("/guestbook", function(req,res){
  
           // res.render("pages/guestbook",{
          db.collection('newmessage').find().toArray(function (err, result)  {
        if (err) return console.log(err)
        res.render('pages/guestbook', {newmessage: result});
  
      });
  
            });
  //Form to insert Guest book messages
        app.get("/newmessage", function(req,res){
            res.sendFile(__dirname  + "/pages/newmessage");
  
            res.render("pages/newmessage",{
                add_newMessage:"Add Your info &amp; message!"
            });
  
        });
  //Accepts users inputs and saves to mongoDB
        app.post("/newmessage" , function(req,res){
          var guestMessage = {
            username:req.body.username,
            country:req.body.country,
            message:req.body.message,
            date:req.body.date
          };
          //assert.equal(null, err);
    db.collection('newmessage').insertOne(guestMessage, function(err, result) {
        if (err) return console.log(err);
        console.log('Message saved to database');
        res.redirect('/guestbook');
      });
  
        });
    app.post("/update/:id", function (req,res){
      var guestMessage = {
            username:req.body.username,
            country:req.body.country,
            message:req.body.message,
            date:req.body.date
          };
          var Gid = req.params.id;
  
      db.collection('newmessage').findById(Gid, {$set: guestMessage}, function(err, result) {
        if (err) return console.log(err);
        result.save(function (err,result) {
         console.log('Message Updated');
            res.redirect('/guestbook');
        })
  
  
      });
  
  
        });
  
    app.get("/delete/: id" , function (req, res) {
       var Gid = req.params.id.toString();
  
       db.collection('newmessage').findById( Gid, function(err, result) {
    result.remove(function (err, result) {
        res.redirect('/guestbook');
    });
  
  
      });
  
  });
  </code></pre>
  
  <blockquote>
    <p>newmessage.ejs</p>
  </blockquote>
  
  <pre><code> &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  
      &lt;% include ../partials/head %&gt;
  &lt;/head&gt;
  
  &lt;body class="container"&gt;
  
      &lt;header&gt;
          &lt;% include ../partials/header %&gt;
      &lt;/header&gt;
      &lt;main&gt;
          &lt;div class="jumbotron"&gt;
  
          &lt;form class="messageForm" method="post" action="/newmessage"&gt;
              &lt;fieldset&gt;
              &lt;legend&gt;&lt;%= add_newMessage %&gt;&lt;/legend&gt;
  
      &lt;div class="form-group"&gt;
        &lt;label for="username"&gt;Username:&lt;/label&gt;
        &lt;input type="text" class="form-control" id="username" name ="username" placeholder="Enter Username"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;label for="country"&gt;Country:&lt;/label&gt;
        &lt;input type="text" class="form-control" id="country"name="country" placeholder="Enter country"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;label for="message"&gt;Message:&lt;/label&gt;
        &lt;input type="text" class="form-control" id="message" name= "message" placeholder="Enter message"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;label for="date"&gt;Date:&lt;/label&gt;
        &lt;input type="date" class="form-control" id="date"name="date" placeholder="Enter date"&gt;
      &lt;/div&gt;
  
      &lt;button type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
  
  
      &lt;/fieldset&gt;
  
  &lt;/form&gt;
  
          &lt;/div&gt;
      &lt;/main&gt;
  
      &lt;footer&gt;
  &lt;% include ../partials/footer %&gt;
  &lt;/footer&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <blockquote>
    <p>guestbook.ejs</p>
  </blockquote>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  
      &lt;% include  ../partials/head %&gt;
  &lt;/head&gt;
  
  &lt;body class="container"&gt;
  
      &lt;header&gt;
          &lt;% include  ../partials/header  %&gt;
  
  
      &lt;/header&gt;
      &lt;main&gt;
          &lt;div class="jumbotron"&gt;
  
             &lt;table  border = "1"&gt;
                 &lt;tr&gt;
  
                      &lt;th&gt;Name&lt;/th&gt;
                      &lt;th&gt;Country&lt;/th&gt;
                      &lt;th&gt;Message&lt;/th&gt;
                       &lt;th&gt;Date&lt;/th&gt;
                         &lt;th&gt;Edit&lt;/th&gt;
                         &lt;th&gt;Delete&lt;/th&gt;
                  &lt;/tr&gt;
  
              &lt;% for(var i=0; i&lt;newmessage.length; i++) {%&gt;
  
  
                  &lt;tr&gt;
  
                      &lt;td class="userInput"&gt;&lt;%= newmessage[i].username %&gt;&lt;/td&gt;
                      &lt;td class="userInput"&gt;&lt;%= newmessage[i].country %&gt;&lt;/td&gt;
                      &lt;td class="userInput"&gt;&lt;%= newmessage[i].message %&gt;&lt;/td&gt;
                      &lt;td class="userInput"&gt;&lt;%= newmessage[i].date %&gt;&lt;/td&gt;
                      &lt;td class="userInput"&gt;&lt;a href="/update/&lt;%= newmessage._id %&gt;"&gt;Update&lt;/a&gt;&lt;/td&gt;
                      &lt;td class="userInput"&gt;&lt;a href="/delete/&lt;%= newmessage._id %&gt;"&gt;Delete&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
  
              &lt;%} %&gt;
              &lt;/table&gt;
  
  
  &lt;/div&gt;
      &lt;/main&gt;
  
       &lt;footer&gt;
  &lt;%  include  ../partials/footer  %&gt;
  &lt;/footer&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/AoiXa.png" rel="nofollow noreferrer">Sample OutPut/image</a></p>