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

    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