JavaScript and TypeScript endpoint discovery

List All Express Routes Without Missing Nested Routers

Express does not publish an official endpoint inventory or OpenAPI document. Many snippets inspect private router internals, which can miss nested routers, mounted prefixes, chained handlers, or behavior that changes between Express versions.

Direct framework method

Start with the routes registered at runtime

A small runtime inspector can enumerate simple top-level routes. Treat the output as a diagnostic aid, not a complete inventory, because it relies on private Express internals rather than a stable public route-discovery API.

Express route inventory · typescript
import type { Express } from "express";

type RouteLayer = {
  route?: {
    path: string;
    methods: Record<string, boolean>;
  };
};

export function listTopLevelRoutes(app: Express): string[] {
  const stack = (app as Express & { _router?: { stack?: RouteLayer[] } })
    ._router?.stack;
  if (!stack) {
    throw new Error("Express router stack is unavailable");
  }

  return stack.flatMap((layer) => {
    if (!layer.route) return [];
    const methods = Object.keys(layer.route.methods)
      .filter((method) => layer.route?.methods[method])
      .map((method) => method.toUpperCase())
      .join(", ");
    return [methods + " " + layer.route.path];
  });
}

Where a route-listing snippet stops

  • Private properties such as _router and stack are not a stable public API.
  • Nested Router instances need recursive traversal with their mounted prefixes preserved.
  • Regular-expression routes and middleware layers require additional decoding.
  • Runtime inspection only sees the application composition that successfully started.

Use source as the second inventory

APIScout analyzes supported Express source registrations, resolves router prefixes, links endpoints back to code, and creates an OpenAPI baseline without relying on a running server's private router stack.

Review supported frameworks

Source scan example

What a source scan finds in an Express app

We ran the APIScout engine on a small Express 4 API built with the patterns that usually break route listings: a versioned API router, routers nested two levels deep, a route() chain, a mount path with a parameter, a constrained parameter, and an async handler wrapper. It read the source without installing dependencies or starting the server, and linked each endpoint back to the file that registered it.

src/app.js
app.use("/api/v1", apiRouter);
app.get("/health", (req, res) => res.json({ status: "ok" }));
src/routes/index.js
router.use("/users", usersRouter);
router.use("/orgs/:orgId/orders", ordersRouter);
src/routes/users.js
router
  .route("/:id")
  .get((req, res) => res.json({ id: req.params.id }))
  .patch((req, res) => res.json({ id: req.params.id }))
  .delete((req, res) => res.sendStatus(204));
src/routes/orders.js
router.post("/", asyncHandler(async (req, res) => {
  const { sku, quantity } = req.body;
  res.status(201).json({ orgId: req.params.orgId, sku, quantity });
}));

router.get("/:orderId(\\d+)", (req, res) => res.json({ orderId: req.params.orderId }));

Endpoints found

GET/api/v1/usersTwo mount prefixes joined; page query parameter
GET, PATCH, DELETE/api/v1/users/{id}One route() chain split into three operations
POST/api/v1/orgs/{orgId}/ordersPrefix parameter orgId; body fields sku and quantity; status 201 through the async wrapper
GET/api/v1/orgs/{orgId}/orders/{orderId}Constrained parameter :orderId(\d+) converted to {orderId}
GET/healthTop-level route

Not resolved from source: paths built in code, such as a template literal like ${PREFIX}/metrics or routes registered in a loop. Compare those with a runtime listing.

Route patterns: the snippet above vs a source scan

Routers mounted with app.use("/api/v1", router) and nested againSkipped: a mounted router is a layer with no routeFound with the full prefix, such as /api/v1/orgs/{orgId}/orders
router.route("/:id").get().patch().delete()One line with all methods, only when the chain is on appEach method listed as its own operation
Mount path parameters (/orgs/:orgId/orders)Not reached, because the router is nestedConverted to the path parameter {orgId}
Constrained parameters (/:orderId(\d+))Printed as writtenConverted to {orderId}
Async wrapper (asyncHandler(async (req, res) => …))Method and path onlyRequest body fields and a status set with res.status()
Paths built in code (template literals, loops)Final values, because the app has runNot resolved; check them against a runtime listing

Questions about listing Express routes

How do I list all routes in an Express app?

Express has no public API for it. At runtime you walk the router stack: top-level routes are layers with a route property, and a mounted router is a layer whose handle has its own stack, which you walk recursively while rebuilding each mount prefix. In Express 4 that prefix is stored only as a regular expression on the layer. Packages such as express-list-endpoints do this walk for you; its README says it supports Express 4 only and omits app.all handlers. From source, APIScout lists routers, chains, and prefixes without starting the app.

Why does app._router.stack miss routes?

It only holds what was registered on the app itself. A router mounted with app.use() appears as a single middleware layer, so its routes are skipped unless you recurse into it. On Express 5 the property no longer exists: the router is exposed as app.router, so the snippet above throws.

Can I generate OpenAPI from Express routes without running the server?

Yes, from source. APIScout reads the route registrations in VS Code, resolves router prefixes, converts :params to {params}, picks up request body fields and statuses set with res.status(), and exports an OpenAPI document. Check routes built from variables or in loops against a runtime listing.

Turn the inventory into a reviewable API contract

Export OpenAPI, review the endpoints with the team that owns them, and use the same contract for documentation and security testing.

Open the source-to-OpenAPI workflow