title: How to send message in DELETE route - express.js
body: <p>I want to show message after deleting user but I don't know how to do it. I tried to create req.session properties and then use them but they are not available in GET route. Do you know how to fix this code?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>router.get("/", mid.isExpired, mid.isLoggedIn, mid.isAdmin, (req, res) =&gt; {
    let currentMessage = req.session.message;
    let currentState = req.session.state;
    req.session.message = undefined;
    req.session.state = undefined;
    console.log(currentState, currentMessage); //undefined
    user.getAll()
      .then(result =&gt; {
        res.render("users", {
          name: req.user,
          users: result,
          msg: currentMessage,
          state: currentState
        })
      })
  });
  
  
  // delete route
  
  router.delete("/delete/:id", mid.isExpired, mid.isLoggedIn, mid.isAdmin, (req, res) =&gt; {
    user.del(req.params.id)
      .then(() =&gt; {
        req.session.message = "Some message!"
        req.session.state = true;
      })
  });
  
  // jquery 
  
  function ajaxDelete(ev, url) {
    ev.preventDefault();
    $.ajax({
      url: url,
      type: "DELETE"
    });
  }
  
  delBtn.click(function(e) {
    var user = $(this).data("user");
    ajaxDelete(e, "/users/delete/" + user);
    window.location.href = "/users";
  })</code></pre>
  </div>
  </div>
  </p>