expressjs/expressMIT9a34acfReport / request removal

Examples: MVC & Route Organization

These examples show several ways to organize an Express application: one exported app, route-related modules, handler maps, and separate application instances. The visible code establishes the construction points, while the omitted route-registration lines limit how far the wiring can be described.

The main reason to compare them is to distinguish application structure from request behavior. The excerpts show which dependencies and modules are introduced, but they do not show every use, route, or hostname pattern.

Sources: examples/multi-router/index.js:5, examples/mvc/index.js:13, examples/route-map/index.js:12, examples/route-separation/index.js:9, examples/vhost/index.js:44, examples/mvc/lib/boot.js:7, examples/mvc/lib/boot.js:8, examples/mvc/lib/boot.js:9, examples/route-separation/index.js:13, examples/route-separation/index.js:14, examples/route-separation/index.js:15, examples/vhost/index.js:9

Core concepts

MVC bootstrapping

MVC bootstrapping is the process of creating the application and loading its supporting modules; the shown boot.js dependencies are express, fs, and path.

Sources: examples/mvc/lib/boot.js:7, examples/mvc/lib/boot.js:8, examples/mvc/lib/boot.js:9

Route separation

Route separation keeps different route concerns in separate modules; the example imports site, post, and user independently.

Sources: examples/route-separation/index.js:13, examples/route-separation/index.js:14, examples/route-separation/index.js:15

Handler maps

A handler map groups related request functions under one object; users contains list, get, and delete handlers, while pets contains list and delete handlers.

Sources: examples/route-map/index.js:31-43, examples/route-map/index.js:45-53

Multiple applications

Multiple applications means constructing more than one Express app instead of placing every behavior on one instance; the vhost example creates main and redirect separately.

Sources: examples/vhost/index.js:21, examples/vhost/index.js:35

Virtual-host dependency

A virtual-host dependency provides the mechanism selected by the example for hostname-based dispatch; the file imports vhost.

Sources: examples/vhost/index.js:9

How the examples build their application boundaries

The common boundary is an Express factory call that produces an application object. The MVC, multi-router, route-map, and route-separation examples each show an application being created, although the route-separation excerpt does not show it being exported.

Example application boundaries — Where do the examples create application instances?

Evidence

The MVC entry point also imports logging, path handling, sessions, and method override alongside Express, so its boot surface is broader than the one-line application construction alone.

The available MVC boot excerpt proves that examples/mvc/lib/boot.js imports express, fs, and path, but it does not show directory scanning, controller loading, registration calls, or how the imported values are used. Therefore, automatic controller wiring cannot be established from this pack.

Sources: examples/multi-router/index.js:5, examples/mvc/index.js:13, examples/route-map/index.js:12, examples/route-separation/index.js:9, examples/mvc/index.js:7, examples/mvc/index.js:8, examples/mvc/index.js:9, examples/mvc/index.js:10, examples/mvc/index.js:11, examples/mvc/lib/boot.js:7, examples/mvc/lib/boot.js:8, examples/mvc/lib/boot.js:9

How route organization differs

The route-separation approach is visibly module-oriented: its entry file imports three local modules named site, post, and user. This supports a split by route concern, but the shown lines do not reveal whether those modules export routers, middleware, or individual handlers.

The multi-router example provides less evidence in the supplied excerpt. It imports Express and creates an exported app, but no router declaration, mount path, or registration call is visible. The name of the example alone is not enough to reconstruct its routing strategy.

The route-map example instead visibly groups operations as functions on users and pets. Those handlers send responses and escape request parameters such as uid and pid before including them in response text.

ExampleVisible organizationEvidence limit
examples/mvcEntry app plus boot dependenciesController discovery is not shown
examples/route-separationSeparate site, post, and user modulesMounting or registration is not shown
examples/multi-routerOne exported app constructionRouter setup is not shown
examples/route-mapusers and pets handler objectsRoute-to-handler mapping is not shown

The table distinguishes what the excerpts demonstrate from what would require additional source lines.

Sources: examples/route-separation/index.js:13, examples/route-separation/index.js:14, examples/route-separation/index.js:15, examples/multi-router/index.js:3, examples/multi-router/index.js:5, examples/route-map/index.js:31-43, examples/route-map/index.js:45-53, examples/mvc/lib/boot.js:7, examples/mvc/lib/boot.js:8, examples/mvc/lib/boot.js:9

How hostname-based dispatch is represented

The vhost example imports vhost, creates a main application, creates a redirect application, and finally creates an exported app. Those separate application instances are the visible pieces of its boundary design.

Vhost application pieces — Which application instances are visible in the vhost example?

Evidence

The supplied lines do not show a call to vhost, a hostname pattern, or the mounting of main and redirect. Consequently, they establish that the example prepares the dependency and multiple apps, but not which hostname selects which application.

Sources: examples/vhost/index.js:9, examples/vhost/index.js:21, examples/vhost/index.js:35, examples/vhost/index.js:44

How it connects

These examples are entry points for the general application and dispatch mechanisms. Read Application Lifecycle for how an app is initialized and started, then App Routing & Request Dispatch for registration and request traversal.

For the router semantics behind mounted or nested routing, continue with Routing Architecture. For request hostname behavior, The Request Object documents the request-side hostname surface, while this pack does not show the vhost registration itself.

The MVC example’s session, method-override, logging, and path dependencies connect to the broader middleware and rendering examples; use Built-in Middleware and Rendering Views for those mechanisms.

Sources: examples/mvc/index.js:13, examples/route-separation/index.js:9, examples/vhost/index.js:9, examples/mvc/index.js:8, examples/mvc/index.js:9, examples/mvc/index.js:10, examples/mvc/index.js:11

Key takeaways

  • The MVC boot excerpt shows dependency imports, not automatic controller discovery.
  • Route separation visibly divides concerns into site, post, and user modules.
  • The multi-router excerpt proves app creation but not router mounting.
  • Route-map organizes handlers in users and pets objects.
  • The vhost excerpt shows multiple apps and the vhost dependency, but not hostname-to-app rules.

Want this for your repos?

Try Angada AI Wiki