Express.js | app.all() Function

Last Updated : 31 Aug, 2026

The app.all() function is used to execute a callback for all HTTP methods on a specified path. It can handle requests such as GET, POST, PUT, DELETE, and other HTTP methods using a single route definition. 

frame_8

Syntax:

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

Parameters:

  • path: The path for which the callback functions are executed.
  • callback: A middleware function or multiple callback functions that are executed for matching requests.

Installation of the express module:

You can visit the link to Install the express module. You can install this package by using this command.

npm install express

After installing the express module, you can check your express version in the command prompt using the command.

npm version express

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:

Screenshot-2026-08-03-153443

Filename: index.js 

javascript
const express = require('express');
const app = express();
const PORT = 3000;
app.all('/user', function (req, res) {
    console.log(`${req.method} request received`);
    res.send(`Handled ${req.method} request`);
});
app.listen(PORT, function () {
    console.log(`Server listening on PORT ${PORT}`);
});

Steps to run the program:

Run the index.js file using the below command:

node index.js

Output:

Console Output:

Server listening on PORT 3000

Browser Output:

Now open your browser and make GET, POST, PUT, DELETE, or any other HTTP request method to http://localhost:3000/user and you will see the following output on the console:

Screenshot-2026-08-21-101311

Working of app.all()

  • A route path is specified using app.all().
  • Express receives a request for that path.
  • The app.all() callback runs for the request regardless of its HTTP method.
  • The callback can perform common logic or middleware operations.
  • Calling next() passes control to the next matching middleware or route.

Use Cases of app.all()

  • Applying common middleware to a specific path.
  • Running authentication or authorization checks.
  • Logging requests for a particular route.
  • Applying common logic to multiple HTTP methods.
  • Handling route-level preprocessing.
Comment