Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
How can I delete a user from my mongoose and node web app?

I have so far got an app where users can register and sign in. I have also implicated a role based system, However I am struggling when it comes to deleting a user. I have looked all over the web but nothing seems to work. I think my delete route is fine, but when I click the delete button nothing happens. I have identified the user id in the url but it doesn't delete. Any help would be much appreciated.

in routes/admin.js

//Delete a user
router.delete('/delete/:id', (req, res, next) => {
  try {
    User.findByIdAndDelete({_id: req.params.id});
  // res.redirect('/admin');
  } catch (error) {
    res.redirect('/index');
  }
});

in views/manage-users.ejs

<form action="/admin/delete/:<%= user.id %>" method="delete">
          <button type="submit">DELETE</button>
      </form>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do like this.

router.delete("/delete/:id",  (req: Request, res: Response) => {
      const id = req.params.id;
    
    
      Links.deleteOne({ _id: id })
        .then((data) =>
          res.json({
            data: data,
          })
        )
        .catch((error) => {
          return res.send(error);
        });
    });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!