Express.js app.all() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

In Express.js, app.all() registers handlers for a path that run for every HTTP method. A request to /secret with GET, POST, PUT, or DELETE all hit the same app.all('/secret', …) stack.

Use it for shared route logic — logging, auth, or loading a user — then call next() so a method-specific route like app.get() can finish the response. It is not a browser API; it runs inside your Express server.

Syntax

Call app.all in your Express.js app. Start with this line.

Express
app.all(path, callback)
app.all(path, ...callbacks)
CallWhat it does
app.all(path, callback)Primary signature.
app.all(path, ...callbacks)Related call form.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

app.all(path, callback)
app.all(path, ...callbacks)

Parameters

ParameterDescription
pathRequired. Route path to match. Strings match the whole path. Arrays match any listed path.
callbackRequired. One or more handlers: (req, res, next) => { … }. Can call next('route') to skip remaining callbacks for this route.

Return Value

app.all() returns the same application object (app), so chaining is possible. In real apps you almost always ignore the return value and register each route on its own line.

Express
// Same app instance comes back — chaining works, but is uncommon:
app.all('/secret', gate).get('/secret', handler);

// Typical style — ignore the return value:
app.all('/secret', gate);
app.get('/secret', handler);

Express.js Examples

Example 1 — Log Every Method on One Path

Print the method and URL for any request to /secret, then continue.

Express
const express = require('express');
const app = express();

app.all('/secret', (req, res, next) => {
  console.log('Accessing the secret section ...');
  next();
});

app.get('/secret', (req, res) => {
  res.send('Secret GET');
});

app.listen(3000);

How It Works

  1. Match the path only. app.all('/secret', …) cares about the path, not the verb.
  2. Log, then continue. console.log runs, then next() hands control to the next matching handler.
  3. GET gets a reply. app.get('/secret') sends Secret GET after the log line.
  4. Other methods still enter app.all. POST or DELETE also log; they only get a body if you add matching routes.

Example 2 — Auth Gate for a Path Prefix

Require a header before any method under /api can continue. Express 5 uses a named splat.

Express
const express = require('express');
const app = express();

app.all('/api/{*splat}', (req, res, next) => {
  if (req.get('x-api-key') !== 'demo-key') {
    return res.status(401).json({ error: 'Unauthorized' });
  }
  next();
});

app.get('/api/profile', (req, res) => {
  res.json({ name: 'Ada' });
});

app.listen(3000);

How It Works

  1. Cover the prefix. /api/{*splat} matches /api/profile and deeper paths in Express 5.
  2. Check once for all methods. GET, POST, and DELETE all hit the same gate.
  3. Deny with a response. Missing key → 401 and no next(), so later routes never run.
  4. Allow with next(). Valid key continues to app.get('/api/profile').

Example 3 — Several Callbacks on One app.all

Chain shared steps on one path: require auth, then attach a user, then answer with GET.

Express
const express = require('express');
const app = express();

function requireAuth(req, res, next) {
  if (!req.get('x-user')) {
    return res.status(401).send('Login required');
  }
  next();
}

function loadUser(req, res, next) {
  req.user = { id: 1, name: req.get('x-user') };
  next();
}

app.all('/account', requireAuth, loadUser);

app.get('/account', (req, res) => {
  res.json(req.user);
});

app.listen(3000);

How It Works

  1. Pass a list of handlers. app.all('/account', requireAuth, loadUser) runs them in order for every method.
  2. Gate first. requireAuth stops with 401 when the header is missing.
  3. Enrich the request. loadUser sets req.user, then calls next().
  4. Answer in the method route. app.get('/account') sends the loaded user as JSON.

Runtime Support

app.all() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not execute it — they only send HTTP requests to your app.

✓ Server · Express 4 & 5

app.all()

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
app.all() Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It registers one or more handlers for a path that run for every HTTP method Express supports — GET, POST, PUT, PATCH, DELETE, and others.
Use app.all() for shared path logic that must run no matter which method arrives — auth checks, logging, or attaching request context — then keep method-specific handlers for the real response.
app.all() is a routing method for a path and all verbs, like app.METHOD(). app.use() mounts middleware (often with a prefix) and is the usual way to attach routers and global middleware.
Yes, if a later handler should run. If you send a response (res.send, res.json, and so on) without calling next(), the chain stops — which is correct for a hard deny like 401. Use next('route') to skip remaining handlers on the current route and try the next matching route.
No. Express runs on a Node.js (or compatible) server. Browsers only send HTTP requests to your server; they do not execute app.all().

Next: app.delete()

Handle HTTP DELETE for a path with a dedicated method route.

app.delete() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful