expressjs/expressMIT9a34acfReport / request removal

Express Overview

Express is a minimalist Node.js web framework for building HTTP servers, APIs, websites, and hybrid applications. Its public surface combines routing, HTTP helpers, content negotiation, and view support.

The package exists to provide small, robust HTTP-server tooling without forcing a particular ORM or template engine. The source entry point is intentionally thin: it assembles an application function, request and response prototypes, and the application methods that implement the framework.

Sources: Readme.md:71-79, Readme.md:121-127, lib/express.js:36-56

Core concepts

The application function

An application is a callable function that receives (req, res, next) and forwards those arguments to app.handle. Calling express() therefore creates a function, not a separate class instance.

Sources: lib/express.js:37-39, lib/express.js:36-56

Request and response prototypes

The returned application exposes app.request and app.response, which are objects created from Express’s request and response modules and linked back to the application through their app property.

Sources: lib/express.js:36-56

Delegated packages

Express keeps several capabilities in separate npm packages: router is the routing dependency, body-parser supplies body-parsing middleware, and serve-static is the static-file dependency exposed through express.static.

PackageExpress capabilityWhat the pack shows
routerRoutingImported as Router by lib/express.js.
body-parserBody parsingImported as bodyParser by lib/express.js.
serve-staticStatic filesDeclared as a runtime dependency; express.static is used as middleware.

Sources: package.json:34-62, examples/static-files/index.js:15-22

What express() creates

The central factory is createApplication. It constructs the callable app, mixes event-emitter behavior and application methods onto it, creates request and response prototypes, initializes the application, and returns the function.

function createApplication() {
  var app = function(req, res, next) {
    app.handle(req, res, next);
  };

  mixin(app, EventEmitter.prototype, false);
  mixin(app, proto, false);

  app.request = Object.create(req, {
    app: { configurable: true, enumerable: true, writable: true, value: app }
  })

This is the key shape to keep in mind: the function is the application entry point, while app.request and app.response expose the prototypes that will be placed on request and response objects.

The factory also calls app.init() before returning. That initialization step is the boundary between constructing the application object and preparing its default application state; the detailed settings and boot process belong in Application Lifecycle.

Application shape — What does express() assemble?

Evidence

Sources: lib/express.js:36-56

How dependencies divide the work

The entry module imports body-parser, node:events, merge-descriptors, the application prototype, the external router package, and the request and response modules. These imports show the assembly points where Express connects its own API to reusable packages and internal modules.

Routing is represented by the external router dependency, while body parsing is represented by body-parser. Static-file support is represented in the package dependency list by serve-static and is consumed through express.static in the static-files example.

The static-files example demonstrates the intended middleware boundary: app.use(express.static(...)) installs static handling, and the middleware checks for a file matching the request path within the supplied directory.

Sources: package.json:34-62, examples/static-files/index.js:15-22

Where to start reading the request lifecycle

Start with lib/express.js and read createApplication first. It explains the returned function, the handle hand-off, the application methods mixed onto the function, the request and response prototypes, and the initialization call.

Then follow the application prototype. Route methods create a route, apply the method-specific handlers, and return the application for chaining; app.all applies handlers to every HTTP method. This is the next step for understanding how application code becomes dispatchable route state.

Reading path — Where should a reader start to follow request handling?

Evidence

From there, continue to App Routing & Request Dispatch and Routing Architecture for dispatch and layered routing. Read Built-in Middleware for the body-parsing and static-file exports. The request and response extensions are covered by The Request Object, Response: Sending Data, and Response: Headers, Cookies & Redirects.

For server startup, follow the application’s listen implementation and then the lifecycle page; the documented contract says the returned Node HTTP server uses the application function as its callback. Application Lifecycle

Sources: lib/express.js:36-56, lib/express.js:37-39, lib/application.js:471-481, lib/application.js:484-503, examples/static-files/index.js:15-22, lib/application.js:577-596

How it connects

The package manifest defines the runtime boundary: Express depends on routing, parsing, static serving, HTTP utilities, and response-support packages, while its published files include index.js and lib/.

The application prototype supplies the higher-level API that callers use after express() returns, including route registration, rendering, and server startup. Those areas continue in App Configuration & Settings, Rendering Views, and Application Lifecycle.

Sources: package.json:34-62, package.json:85-89, lib/application.js:471-503, lib/application.js:505-522, lib/application.js:577-596

Key takeaways

  • express() returns a callable app function that forwards requests to app.handle.
  • The returned app exposes app.request and app.response, each linked back to the app.
  • Routing, body parsing, and static files are connected through router, body-parser, and serve-static/express.static.
  • Start reading at lib/express.js, then follow the application prototype into request dispatch and middleware.

Sources: lib/express.js:36-56, lib/express.js:37-39, package.json:34-62, examples/static-files/index.js:15-22, lib/application.js:471-503

Want this for your repos?

Try Angada AI Wiki