Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Module

app.route

Creates a chainable Route for one path, allowing handlers for multiple HTTP verbs to be declared together. It keeps the path in one place, reducing duplication and typos.

Since
4.0.0

How it works

app.route(path) creates one route object for the supplied path. Chain methods such as .get(), .post(), and .all() on the returned object to attach handlers, keeping the path in one place.

Syntax

app.route(path)

Parameters

NameTypeDescription
pathStringThe path of the route to create.

Returns

Route

Key points

  • Use app.route(path) when several HTTP methods belong to the same path.
  • Defining the path once reduces repetition and makes related handlers easier to maintain.
  • A single route declaration helps prevent inconsistent copies of the same path.
  • The returned Route lets you chain verb handlers and optional middleware for that path.

Common mistakes

  • The returned value is a Route object; HTTP handlers are added by chaining route methods rather than by treating it as a response handler.

Example: Chain handlers for one path

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

app.route('/books')
  .get((req, res) => res.json([{ title: 'Dune' }]))
  .post((req, res) => res.status(201).send('Created'));

app.listen(3000);

Creates one chainable route definition and attaches handlers for multiple HTTP verbs.

When to use it

Group resource handlers

Several methods such as GET and POST operate on the same resource path.

Apply route-specific middleware

A route needs shared middleware before method-specific handlers.

Reduce path duplication

A codebase has repeated path strings across verb declarations.

Interview questions

QWhat does app.route() return, and how is it used?

app.route(path) creates a single Route for the path and returns it. HTTP verb handlers can then be chained on that Route, such as .get() and .post().

Follow-up: Why use it instead of separate app.get() and app.post() calls? It keeps the path in one location, reducing duplicated route names and typo risk.

QWhat argument does app.route() accept?

Its path argument is a string identifying the route to create. The returned Route supports HTTP verbs with optional middleware.

Follow-up: How would you apply logic to every verb on that path? Chain .all() before the verb-specific handlers.

QWhen is app.route() useful?

It supports chainable handlers for one route path, allowing multiple HTTP methods to be declared together. This makes route definitions more modular and avoids repeating the path.

Follow-up: What alternative provides mountable modular route handlers? Use express.Router() for router-level organization.

  • app.METHOD
  • app.param
  • express.Router
  • Route

Source: Application Object - Express.js 4.x. Checked 2026-10-15.