devnotes.

router.all() Function

router.all() works like router.METHOD(), but matches every HTTP method for a given path — handy for global logic on a specific prefix.

Syntax

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

Example

const express = require("express");
const app = express();
const router = express.Router();
const PORT = 5000;

router.all("/items", (req, res) => {
    console.log("Any method matched /items");
    res.send(`Handled ${req.method} on /items`);
});

app.use(router);

app.listen(PORT, () => console.log(`Listening on ${PORT}`));

GET, POST, PUT, or DELETE requests to /items all reach the same handler.

Use cases

  • Logging or authenticating requests to a specific path regardless of method.
  • Applying a maintenance-mode response to certain routes.
  • Running shared preprocessing before more specific handlers take over.
router.all() Function | DevNotes