Express.js router.route() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Router

Definition

In Express.js, router.route(path) returns a Route for one path on an express.Router() so you can chain HTTP verbs — .get(), .post(), .put(), .delete(), .all(), and more — without repeating the path string.

Official tip: use it to avoid duplicate route names and typos. Matching rules are the same as separate router.METHOD() calls. The path is relative to the mount. The app-level twin is app.route().

Syntax

Call router.route in your Express.js app. Start with this line.

Express
router.route(path)
.all(callback)
.get(callback)
.post(callback)
CallWhat it does
router.route(path)Primary signature.
.all(callback)Related call form.
.get(callback)Related call form.
.post(callback)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();

router.route(path)
.all(callback)
.get(callback)
.post(callback)

Parameters

ParameterDescription
pathRequired. Path relative to the router’s mount. Same matching rules as other router.METHOD routes — strings match the whole remaining path.

Return Value

router.route(path) returns a Route instance. Each chained method returns the same route so you can keep chaining.

Express
router.route('/book')
  .all(log)
  .get(list)
  .post(create);

Express.js Examples

Example 1 — Mounted /book Chain

Official-style verbs on one path. After the mount, the public URL is /catalog/book.

Express
const express = require('express');
const app = express();
const catalog = express.Router();

catalog
  .route('/book')
  .get((req, res) => {
    res.send('Get a book');
  })
  .post((req, res) => {
    res.status(201).send('Add a book');
  })
  .put((req, res) => {
    res.send('Update the book');
  });

app.use('/catalog', catalog);
app.listen(3000);

How It Works

  1. One path. catalog.route('/book') creates the Route on the module.
  2. Chain verbs. .get, .post, and .put share that path string.
  3. Mount adds the prefix. app.use('/catalog', catalog) makes the public URL /catalog/book.
  4. Fewer typos. /book appears once — not three times.

Example 2 — With router.param()

Docs pattern: preload :user_id, then chain .all, .get, and .put on the same path.

Express
const express = require('express');
const app = express();
const users = express.Router();

users.param('user_id', (req, res, next, id) => {
  req.user = { id, name: 'TJ' };
  next();
});

users
  .route('/users/:user_id')
  .all((req, res, next) => {
    // route-specific middleware for every verb
    next();
  })
  .get((req, res) => {
    res.json(req.user);
  })
  .put((req, res) => {
    req.user.name = String(req.body?.name || req.user.name);
    res.json(req.user);
  });

app.use(express.json());
app.use('/api', users);
app.listen(3000);

How It Works

  1. Param first. users.param('user_id') loads req.user once for this request.
  2. Reuse the path. route('/users/:user_id') names the resource once.
  3. .all runs for every verb. Call next() so .get / .put can answer.
  4. Mount. Public URLs sit under /api.

Example 3 — Shared .all() Check

Require a header for every method on the path, then handle GET/POST.

Express
const express = require('express');
const app = express();
const admin = express.Router();

admin
  .route('/stats')
  .all((req, res, next) => {
    if (req.get('x-admin') !== 'yes') {
      return res.status(401).json({ error: 'unauthorized' });
    }
    next();
  })
  .get((req, res) => {
    res.json({ users: 12 });
  })
  .post((req, res) => {
    res.status(201).json({ ok: true });
  });

app.use('/admin', admin);
app.listen(3000);

How It Works

  1. Guard once. .all checks the header for every verb on /stats.
  2. Deny early. Missing header sends 401 and skips later handlers.
  3. Allow with next(). Valid requests reach .get or .post.
  4. Mount. Public paths are under /admin.

Runtime Support

router.route() is an Express.js router method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send HTTP requests.

✓ Server · Express 4 & 5

router.route()

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

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
router.route() 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 returns a Route instance for one path on a router so you can chain .get(), .post(), .put(), .delete(), .all(), and other HTTP methods without repeating the path string.
Official reason: avoid duplicate path strings and typo errors. It also keeps related handlers together inside a module.
Same chaining idea. router.route() lives on an express.Router(), so the path is relative to where you mount that router with app.use().
It runs for every HTTP verb on that path first — useful as route-specific middleware before .get() or .post(). It can run even when no matching method handler exists.
No. It is a server-side Express routing helper on Node.js.

Next: router.use()

Mount middleware and nested routers with a path prefix.

router.use() 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