devnotes.

app.delete() Function

app.delete() defines a route that handles HTTP DELETE requests for a given path.

Syntax

app.delete(path, callback [, callback ...])

Example

const express = require("express");
const app = express();
const PORT = 4900;

app.delete("/products/:id", (req, res) => {
    res.send(`Product ${req.params.id} deleted`);
});

app.listen(PORT, () => console.log(`Listening on ${PORT}`));

A DELETE request to /products/12 responds with Product 12 deleted.

Use cases

  • Removing a resource identified by a route parameter.
  • Building DELETE endpoints for RESTful APIs.
  • Deleting records from a database in response to a client request.
app.delete() Function | DevNotes