The app object is instantiated on creation of the Express server. It has a middleware stack that can be customized in app.configure()(this is now deprecated in version 4.x).
To setup your middleware, you can invoke app.use(<specific_middleware_layer_here>) for every middleware layer that you want to add (it can be generic to all paths, or triggered only on specific path(s) your server handles), and it will add onto your Express middleware stack. Middleware layers can be added one by one in multiple invocations of use, or even all at once in series with one invocation. See use documentation for more details.
To give an example for conceptual understanding of Express Middleware, here is what my app middleware stack (app.stack) looks like when logging my app object to the console as JSON:
stack:
[ { route: '', handle: [Function] },
{ route: '', handle: [Function: static] },
{ route: '', handle: [Function: bodyParser] },
{ route: '', handle: [Function: cookieParser] },
{ route: '', handle: [Function: session] },
{ route: '', handle: [Function: methodOverride] },
{ route: '', handle: [Function] },
{ route: '', handle: [Function] } ]
As you can see, I used app.use(express.bodyParser()), app.use(express.cookieParser()), and other methods to add these express middleware 'layers' to the middleware stack. The routes are blank because I stated that those middleware layers should be triggered on any route when I added them. In the stack printed above, if I built a custom middleware layer that only triggered on the path /user/:id, it would be reflected as a string in the route field of that middleware layer object.
Each layer effectively adds a function to your middleware flow that particularly handles something.
For example, by including bodyParser, you're ensuring that your server uses the express middleware to handle incoming requests. So, because you called app.use, your middleware now parses the body of incoming requests as part of the method for handling incoming requests app.use(bodyParser).