Express.js DELETE Method: How to Delete Data from an API
Aug 12,2026

In the previous articles, we learned how to work with different HTTP methods in Express.js:

  • GET — retrieve data
  • POST — create data
  • PUT — replace or update data
  • PATCH — partially update data

There is one more important operation in CRUD:

DELETE

As the name suggests, the DELETE method is used when we want to remove a resource.

For example:

DELETE /api/users/10

This tells the server:

Delete the user whose ID is 10.

In this article, we'll learn how to create DELETE APIs in Express.js from scratch.

We'll cover:

  • What the DELETE method is
  • How app.delete() works
  • Route parameters with DELETE
  • Deleting data from an array
  • Handling non-existing resources
  • HTTP status codes
  • Validation
  • Soft delete vs hard delete
  • DELETE with a database
  • Common mistakes
  • A complete CRUD example

Let's get started.


What Is the HTTP DELETE Method?

The HTTP DELETE method is used to remove a resource from a server.

For example:

DELETE /api/users/10

The server receives the request and removes user 10.

Before the request:

{
  "id": 10,
  "name": "John",
  "email": "john@example.com"
}

After a successful DELETE:

User 10 no longer exists

A simple way to remember the HTTP methods is:

GET
↓
Read

POST
↓
Create

PUT
↓
Replace

PATCH
↓
Partially update

DELETE
↓
Remove

Together, these operations form the foundation of CRUD APIs.


Creating an Express.js Project

If you haven't already created an Express application, run:

mkdir express-delete-api
cd express-delete-api
npm init -y
npm install express

Create a file:

server.js

Our project can look like this:

express-delete-api/
│
├── node_modules/
├── package.json
└── server.js

Step 1: Create the Express Server

Start with a basic Express server:

const express = require("express");

const app = express();

const PORT = 3000;

app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
});

Run the application:

node server.js

You should see:

Server running on http://localhost:3000

Step 2: Create Sample Data

For this tutorial, we'll use an array instead of a database.

const users = [
  {
    id: 1,
    name: "John",
    email: "john@example.com"
  },
  {
    id: 2,
    name: "Jane",
    email: "jane@example.com"
  },
  {
    id: 3,
    name: "David",
    email: "david@example.com"
  }
];

Our data currently looks like:

User 1 → John
User 2 → Jane
User 3 → David

We'll create an API that allows us to delete any of these users.


Step 3: Create a DELETE Route

Express provides the app.delete() method for handling DELETE requests.

The basic syntax is:

app.delete("/route", (req, res) => {
  // Delete logic
});

For our users:

app.delete("/api/users/:id", (req, res) => {
  // Delete user
});

Here:

/api/users/:id

contains a route parameter.

For example:

DELETE /api/users/2

The value:

2

can be accessed using:

req.params.id

Step 4: Get the User ID

Let's retrieve the ID:

app.delete("/api/users/:id", (req, res) => {
  const userId = Number(req.params.id);

  console.log(userId);

  res.json({
    message: "Delete request received"
  });
});

If we send:

DELETE /api/users/2

then:

req.params.id

will contain:

"2"

Notice that route parameters are received as strings.

That's why we convert it:

Number(req.params.id)

Now we have:

2

as a number.


Step 5: Find the User

Before deleting a user, we should check whether the user exists.

We can use findIndex():

const userIndex = users.findIndex(
  (user) => user.id === userId
);

Suppose:

userId = 2

The result will be:

1

because the user with ID 2 is at array index 1.

If the user doesn't exist:

userIndex = -1

So we can check:

if (userIndex === -1) {
  return res.status(404).json({
    message: "User not found"
  });
}

Step 6: Delete the User

For an array, we can use:

splice()

Example:

users.splice(userIndex, 1);

The first argument tells JavaScript where to start deleting.

The second argument tells it how many items to remove.

So:

users.splice(userIndex, 1);

means:

Remove one user starting from this index.


Complete DELETE API

Now let's put everything together:

app.delete("/api/users/:id", (req, res) => {
  const userId = Number(req.params.id);

  const userIndex = users.findIndex(
    (user) => user.id === userId
  );

  if (userIndex === -1) {
    return res.status(404).json({
      message: "User not found"
    });
  }

  users.splice(userIndex, 1);

  res.status(200).json({
    message: "User deleted successfully"
  });
});

That's our first working DELETE API.


Testing the DELETE API

Start your server:

node server.js

Then use Postman, Insomnia, Thunder Client, or any API testing tool.

Send:

DELETE http://localhost:3000/api/users/2

If the user exists, the response will be:

{
  "message": "User deleted successfully"
}

Before the request:

[
  {
    "id": 1,
    "name": "John",
    "email": "john@example.com"
  },
  {
    "id": 2,
    "name": "Jane",
    "email": "jane@example.com"
  },
  {
    "id": 3,
    "name": "David",
    "email": "david@example.com"
  }
]

After:

[
  {
    "id": 1,
    "name": "John",
    "email": "john@example.com"
  },
  {
    "id": 3,
    "name": "David",
    "email": "david@example.com"
  }
]

User 2 has been removed.


What Happens If the User Doesn't Exist?

Suppose we send:

DELETE /api/users/100

but there is no user with ID 100.

Our code finds:

userIndex === -1

and returns:

{
  "message": "User not found"
}

with:

404 Not Found

This is important.

We shouldn't return:

200 OK

and say:

"User deleted successfully"

when the user never existed.

The API response should accurately describe what happened.


Why Do We Use return?

Consider this code:

if (userIndex === -1) {
  res.status(404).json({
    message: "User not found"
  });
}

users.splice(userIndex, 1);

There's a problem.

Even after sending the 404 response, JavaScript could continue executing the code below it.

Instead, use:

if (userIndex === -1) {
  return res.status(404).json({
    message: "User not found"
  });
}

The return stops the current route handler.

This is a very common pattern in Express:

if (error) {
  return res.status(400).json({
    message: "Something went wrong"
  });
}

DELETE Usually Doesn't Need a Request Body

Unlike POST, PUT, and PATCH, DELETE usually doesn't need a request body when deleting a resource by ID.

For example:

DELETE /api/users/10

is enough.

The resource ID is part of the URL:

/api/users/:id

and is accessed using:

req.params.id

You generally don't need:

{
  "id": 10
}

in the request body.


DELETE Multiple Resources

Sometimes an application needs to delete multiple resources.

For example, an admin dashboard might allow selecting multiple users:

User 1 ✓
User 2 ✓
User 3
User 4 ✓

The frontend might send:

DELETE /api/users

with:

{
  "ids": [1, 2, 4]
}

However, bulk deletion is an API design decision and should be handled carefully.

For example:

app.delete("/api/users", (req, res) => {
  const { ids } = req.body;

  // Validate ids
  // Delete selected users
});

For a simple API, though, deleting a single resource is usually:

DELETE /api/users/:id

DELETE with Query Parameters

You may also see APIs such as:

DELETE /api/users?id=10

Then:

req.query.id

would contain:

10

But when identifying a specific resource, this:

DELETE /api/users/10

is usually clearer than:

DELETE /api/users?id=10

because 10 represents the specific user resource.


Returning the Deleted Resource

Sometimes you may want to return information about the deleted resource.

For example:

app.delete("/api/users/:id", (req, res) => {
  const userId = Number(req.params.id);

  const userIndex = users.findIndex(
    (user) => user.id === userId
  );

  if (userIndex === -1) {
    return res.status(404).json({
      message: "User not found"
    });
  }

  const deletedUser = users.splice(userIndex, 1)[0];

  res.status(200).json({
    message: "User deleted successfully",
    user: deletedUser
  });
});

Now the response might be:

{
  "message": "User deleted successfully",
  "user": {
    "id": 2,
    "name": "Jane",
    "email": "jane@example.com"
  }
}

This can be useful when the frontend needs to display a confirmation or update local state.


Using 204 No Content

Another common response for a successful DELETE is:

204 No Content

For example:

app.delete("/api/users/:id", (req, res) => {
  const userId = Number(req.params.id);

  const userIndex = users.findIndex(
    (user) => user.id === userId
  );

  if (userIndex === -1) {
    return res.status(404).json({
      message: "User not found"
    });
  }

  users.splice(userIndex, 1);

  res.status(204).send();
});

A 204 response means:

The request was successfully processed, and there is no response body.

You should not send JSON along with a 204 response.

So this is not appropriate:

res.status(204).json({
  message: "User deleted successfully"
});

If you want to send a JSON message, use:

200 OK

instead.


200 vs 204 for DELETE

Both can be useful.

Use 200 when returning a response body

res.status(200).json({
  message: "User deleted successfully"
});

Use 204 when there is nothing to return

res.status(204).send();

For beginner projects, 200 is often easier because you can return a useful response message.


Hard Delete vs Soft Delete

Here's an important concept you'll encounter in real applications.

There are two common ways to "delete" data.

Hard Delete

The record is actually removed from the database.

For example:

await User.findByIdAndDelete(id);

The record no longer exists.

This is called a hard delete.


Soft Delete

With a soft delete, we don't actually remove the record.

Instead, we mark it as deleted.

For example:

{
  "id": 10,
  "name": "John",
  "isDeleted": true
}

The record still exists in the database, but the application treats it as deleted.

Another common approach is:

{
  "id": 10,
  "name": "John",
  "deletedAt": "2026-08-12T10:30:00Z"
}

Then normal queries can ignore deleted records.

For example:

User.find({
  deletedAt: null
});

Why Use Soft Delete?

Soft deletion can be useful when:

  • Data needs to be restored
  • You need an audit trail
  • Business records shouldn't be permanently removed
  • You need to track historical information
  • Accidental deletion is a concern

For example, in an admin dashboard, instead of permanently deleting a user:

Delete User
     ↓
isDeleted = true

Later, an administrator could restore the account.


DELETE from a React Frontend

Suppose you're calling the Express API from React.

You can use fetch():

const deleteUser = async (userId) => {
  const response = await fetch(
    `http://localhost:3000/api/users/${userId}`,
    {
      method: "DELETE"
    }
  );

  const data = await response.json();

  console.log(data);
};

Then:

deleteUser(10);

will send:

DELETE /api/users/10

You can also use Axios:

await axios.delete(
  `http://localhost:3000/api/users/${userId}`
);

The frontend doesn't need to send a request body for a typical single-resource DELETE operation.


Common Mistakes

1. Using POST for Deletion

You might see:

POST /api/delete-user

Although this can technically be implemented, it's not a good REST-style design when the operation is clearly a deletion.

Prefer:

DELETE /api/users/:id

2. Forgetting to Convert the ID

Suppose your data contains:

{
  id: 10
}

but:

req.params.id

returns:

"10"

Then this comparison can fail:

user.id === req.params.id

because:

10 === "10"

is:

false

Convert it:

const userId = Number(req.params.id);

Then:

user.id === userId

works as expected.


3. Not Checking if the Resource Exists

Don't blindly delete:

users.splice(userIndex, 1);

without checking:

if (userIndex === -1)

Otherwise, you can end up with unexpected behavior.

Always validate that the resource exists first.


4. Returning 200 for Every Situation

Avoid returning:

{
  "message": "User deleted successfully"
}

when:

  • The ID is invalid
  • The user doesn't exist
  • The database failed

Use appropriate status codes.


Useful HTTP Status Codes for DELETE

Here are some common responses:

200 OK

The deletion was successful and you're returning a response body.

200 OK

204 No Content

The deletion was successful and there is no response body.

204 No Content

400 Bad Request

The request contains invalid data.

400 Bad Request

For example:

Invalid ID format

401 Unauthorized

Authentication is required.

401 Unauthorized

403 Forbidden

The user is authenticated but doesn't have permission to delete the resource.

403 Forbidden

404 Not Found

The requested resource doesn't exist.

404 Not Found

500 Internal Server Error

Something unexpected happened on the server.

500 Internal Server Error

DELETE with Authentication

In production applications, you shouldn't allow every user to delete every resource.

For example:

DELETE /api/users/10

might require authentication.

A request might contain:

Authorization: Bearer <token>

Your API could then verify:

Is the user authenticated?
        ↓
Does the user have permission?
        ↓
Does the resource exist?
        ↓
Delete resource

This is especially important for admin APIs.

For example, a normal user shouldn't necessarily be able to send:

DELETE /api/users/1

and delete another user.


A Production-Oriented DELETE Flow

A more realistic DELETE API looks like this:

Client
  ↓
DELETE /api/users/:id
  ↓
Authentication
  ↓
Authorization
  ↓
Validate ID
  ↓
Find resource
  ↓
Check resource exists
  ↓
Delete / Soft Delete
  ↓
Return response

This is much closer to what you'll see in production applications.


Complete Example

Here's the complete beginner-friendly Express example:

const express = require("express");

const app = express();

const PORT = 3000;

const users = [
  {
    id: 1,
    name: "John",
    email: "john@example.com"
  },
  {
    id: 2,
    name: "Jane",
    email: "jane@example.com"
  },
  {
    id: 3,
    name: "David",
    email: "david@example.com"
  }
];

app.delete("/api/users/:id", (req, res) => {
  // Get ID from route parameter
  const userId = Number(req.params.id);

  // Find the user
  const userIndex = users.findIndex(
    (user) => user.id === userId
  );

  // Check whether the user exists
  if (userIndex === -1) {
    return res.status(404).json({
      message: "User not found"
    });
  }

  // Delete the user
  const deletedUser = users.splice(userIndex, 1)[0];

  // Send response
  res.status(200).json({
    message: "User deleted successfully",
    user: deletedUser
  });
});

app.listen(PORT, () => {
  console.log(
    `Server running on http://localhost:${PORT}`
  );
});

Complete CRUD API

At this point, we've covered all four major CRUD operations.

A typical Express API can look like this:

GET
/api/users
/api/users/:id

POST
/api/users

PUT
/api/users/:id

PATCH
/api/users/:id

DELETE
/api/users/:id

The complete CRUD flow is:

                CRUD
                 |
      ------------------------
      |          |           |
    Create      Read       Update       Delete
      |          |           |           |
    POST        GET      PUT/PATCH      DELETE

This pattern is used across many applications:

  • User management
  • Blog platforms
  • E-commerce applications
  • Admin dashboards
  • Learning platforms
  • Social applications
  • Booking systems
  • SaaS applications

Final Thoughts

The DELETE method is one of the simplest HTTP methods to implement in Express.js, but production applications require more than simply removing a record.

The basic route is:

app.delete("/api/users/:id", (req, res) => {
  // Delete resource
});

The ID can be accessed using:

req.params.id

A typical deletion flow is:

Get ID
  ↓
Validate ID
  ↓
Find resource
  ↓
Check resource exists
  ↓
Delete resource
  ↓
Return response

For a simple application, you might use:

users.splice(userIndex, 1);

With MongoDB and Mongoose, you might use:

await User.findByIdAndDelete(id);

And in production, you may also need:

Authentication
Authorization
Validation
Error handling
Soft deletion
Audit logging

The most important thing to remember is that DELETE is not just about removing data. A well-designed DELETE API should also make sure that the requester is allowed to delete the resource, the resource exists, the input is valid, and the client receives an accurate response.

With GET, POST, PUT, PATCH, and DELETE, you now have the foundation needed to build REST APIs with Express.js.