skip to Main Content
const express = require('express');
const app = express();

app.use(express.json());

app.delete('/', (req, res) => {
    res.send('Deleted successfully');
    console.log('this is delete');
});

const port = 2222;
app.listen(port, () => {
    console.log('Server is running on port 2222');
});

Pose specific questions related to the problem you’re facing. For example, you might ask for suggestions on how to debug a "404 Not Found" error when making DELETE requests to an Express server.

2

Answers


  1. Middleware Ordering: Make sure that the app.use(express.json()) middleware is placed before the app.delete() route declaration. Middlewares should generally be declared before route handlers to ensure they are executed in the correct order.

    Route Definition: Ensure that you’re sending a DELETE request to the correct URL. In your case, it’s the root URL ‘/’, as specified in app.delete(‘/’).

    HTTP Method: Double-check that you’re sending a DELETE request to the server. If you’re testing it with a tool like Postman or through a client-side application, ensure that the request method is set to DELETE.

    Express Version: app.delete() is a feature of Express, so ensure that you’re using a version of Express that supports it. However, app.delete() is a standard feature of Express and has been supported for a long time, so this is less likely to be the issue.

    go through with this point that can be help

    Login or Signup to reply.
  2. You have used app.delete but you need to use router.delete, you can refer this link how routes are implemented using express js git example

    const router = express.Router()
    router.delete('/users/:userId', (req, res) => {
      res.send('Deleted successfully');
      console.log('this is delete');
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search