Express app.delete() Function
The `app.delete()` function is utilized to handle HTTP DELETE requests for a specified path. It takes the path as a parameter and also accepts callback functions as parameters to handle the request.
Syntax:Â
app.delete(path, callback)
Parameters:Â
- path: It is the path for which the middleware function is being called.
- callback: It is a middleware function or a series/array of middleware functions.Â
Steps to Install the express module:
Step 1: You can install this package by using this command.
npm install express
Step 2: After installing the express module, you can check your express version in the command prompt using the command.
npm version express
Step 3: After that, you can just create a folder and add a file, for example, index.js. To run this file you need to run the following command.
node index.js
Project Structure:
The updated dependencies in package.json file will look like:
"dependencies": {
"express": "^4.18.2",
}
Example: Below is the example of the app.delete() Function:
Javascript
const express = require( 'express' );
const app = express();
const PORT = 3000;
app. delete ( '/' ,
(req, res) => {
res.send( "DELETE Request Called" )
})
app.listen(PORT,
function (err) {
if (err) console.log(err);
console.log( "Server listening on PORT" , PORT);
});
|
Steps to run the program:Â
node index.js
Console Output:
Server listening on PORT 3000
Browser Output: Now make a DELETE request to http://localhost:3000/ and you will get the following output:Â
DELETE Request Called
We have a complete list of all the important Express Application Module methods, to check those please go through Express Application Complete Reference article
Last Updated :
25 Jan, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...