Express.js app.route() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

In Express.js, app.route(path) returns a Route for one path 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 app.get() / app.post() calls. For larger modules, prefer a Router.

Syntax

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

Express
app.route(path)
.all(callback)
.get(callback)
.post(callback)
CallWhat it does
app.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();

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

Parameters

ParameterDescription
pathRequired. The path for this route (same path rules as other app.METHOD routes — strings match the whole path).

Return Value

app.route(path) returns a Route instance. Each chained method (.get, .post, …) returns that same route so you can keep chaining handlers for one path.

Express
app.route('/book')
  .get(list)
  .post(create)
  .put(replace);

Express.js Examples

Example 1 — Official /events Chain

Docs-style: .all first, then .get and .post.

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

app.use(express.json());

app
  .route('/events')
  .all((req, res, next) => {
    console.log('route middleware', req.method);
    next();
  })
  .get((req, res) => {
    res.json({ events: [] });
  })
  .post((req, res) => {
    res.status(201).json({ created: req.body || {} });
  });

app.listen(3000);

How It Works

  1. One path. app.route('/events') creates the Route.
  2. .all first. Runs for every verb — call next() to continue.
  3. .get / .post. Only the matching method handler responds.
  4. No path typos. The string /events appears once.

Example 2 — CRUD on One Path

Read, replace, and delete the same resource URL.

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

app.use(express.json());

let book = { id: '1', title: 'Node Basics' };

app
  .route('/book')
  .get((req, res) => {
    res.json(book);
  })
  .put((req, res) => {
    book = { id: book.id, title: String(req.body.title || book.title) };
    res.json(book);
  })
  .delete((req, res) => {
    book = null;
    res.status(204).end();
  });

app.listen(3000);

How It Works

  1. Shared URL. All three verbs target /book.
  2. GET reads. Returns the current object.
  3. PUT replaces. Updates fields from req.body.
  4. DELETE clears. Ends with 204 and no body.

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();

app.use(express.json());

app
  .route('/admin/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.listen(3000);

How It Works

  1. Guard once. .all runs before GET and POST.
  2. Fail early. Missing header returns 401 and stops.
  3. next() continues. Allowed requests reach the method handler.
  4. Still one path. Auth logic is not copied into each verb.

Runtime Support

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

✓ Server · Express 4 & 5

app.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
app.route() Express on Node.js

Bottom line: Run examples with Node.js and the express package, then try GET/POST on the same path.

Frequently Asked Questions

It returns a Route instance for one path 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 and readable.
It runs for every HTTP verb on that path first — useful as route-specific middleware before .get() or .post().
No. app.route(path) builds one path’s method chain. express.Router() (see Router overview) mounts a mini-app. Express 5 also has app.router as the app’s built-in router instance.
No. It is a server-side Express routing helper on Node.js.

Next: Router overview

Build modular route groups with express.Router().

Router 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