Resource deletion
Expose a REST endpoint that removes a resource identified by a route parameter.
Express.js · Module
app.delete() registers callback functions for HTTP DELETE requests matching a specified path. The path supports strings, patterns, regular expressions, or arrays of these forms.
Calling app.delete() registers route handling for HTTP DELETE requests that match the supplied path. The path may be a string, regular expression, or array, and one or more callback functions process matching requests.
app.delete(path, callback [, callback ...])| Name | Type | Description |
|---|---|---|
path | String | RegExp | Array | Route path matched against incoming requests; it may be a string, path pattern, regular expression, or array of combinations. |
callback functions | Function | One or more callback functions invoked for matching requests. |
Not specified on the documentation page.
const express = require('express');
const app = express();
app.delete('/users/:id', (req, res) => {
res.send(`Deleted user ${req.params.id}`);
});
app.listen(3000);This runnable Express app registers a handler for DELETE requests whose path includes a user ID.
Expose a REST endpoint that removes a resource identified by a route parameter.
Run authorization or validation before the deletion handler.
Match several equivalent DELETE paths or patterns through one route declaration.
app.delete() registers callbacks for HTTP DELETE requests matching a specified path. The path can be a string, regular expression, or array of those forms.
Follow-up: How could one support several path forms with one registration? Pass an array containing the desired string, pattern, or regular-expression path values.
The method receives a path followed by callback functions. Express invokes those callbacks when a DELETE request matches the path.
Follow-up: How can route processing be shared before the final handler? Supply multiple callbacks so earlier callbacks can perform middleware work and pass control onward.
app.del() is an older alias that existed because delete was reserved in older JavaScript engines. It is deprecated in Express 4.2.0 and later, so app.delete() is the supported spelling.
Follow-up: What migration change is needed when moving to Express 5? Replace app.del() calls with app.delete(), because Express 5 no longer supports the alias.
app.METHOD()app.get()app.post()app.put()app.all()app.use()app.del()