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

315
Views
Express DELETE 500 (Internal Server Error)

I'm trying to Remove my User from the system, but I'm getting error 500 (Internal Server Error)

I tried this with my Product and it still works fine. I didn't know where did I go wrong?

Below is my code

Router

router.get('/user-list/remove/:user_id', adminController.removeUser);

Service

async removeUser(user_id) {
    const userInDb = await this.userRepository.getById(user_id);
    if (userInDb) {
        await userInDb.destroy();
    } else {
        throw new Error();
    }
}

Controller

const removeUser = async (req, res) => {
try {
    const adminService = new AdminService();
    const data = req.params.user_id;
    await adminService.removeUser(data);
    res.send();
} catch (error) {
    res.status(500).json({ TRAVE: true, message: error });
}}

EJS

<a>
    <button class="deletebutton" value="<%= users[i].user_id %>">Delete</button>
</a>

<script type="text/javascript">
            $('.deletebutton').on("click", function (event) {
                event.preventDefault();
                var user_id = $(this).val();
                if (confirm("Are you sure you want to delete this data?")) {
                    $.ajax({
                        url: `/admin/user-list/remove/${user_id}`,
                        method: 'get',
                        data: { user_id: user_id },
                        success: function (data, textStatus, xhr) {
                            if (xhr.status == 200 || xhr.status == '200') {
                                $('.notification').html(`Delete done!`)
                            } else {
                                alert('Some error occurred try again');
                            }
                        },
                        error: function (response) {
                            error.html(`${response.responseJSON.message}`);
                        }
                    });
                }
            });
        </script>

And this is what I get from Console.log

GET http://localhost:5000/admin/user-list/remove/2?user_id=2 500 (Internal Server Error)

I tried with router.delete and method: 'delete' in the script but I get the same result. Where have I encountered the problem? I have a Product table, I have user_id as a foreign key, is it a problem?

about 4 years ago · Juan Pablo Isaza
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!