I have to admit I'm rather surprised I didn't find any info on this through Google. Perhaps I wasn't looking hard enough.
Basically, I want to find information on the various middleware functions my Express.js app is using, preferably via a bash-like console. Logging the express() function itself does not log the sub-functions, such as trace() or mkcol(). These are shown as attributes of the express function object, as, for example, trace: [Function], or emit: [Function: emit]; their bodies and current contents are not shown. I am able to log the function bodies through e.g. express().once.toString(), as said in several answers, including this one.
This only shows the function body as it was before I called it (when I added all the middleware), not what said body is now. It does not show the middleware I had Express use().
How do I show these middleware functions in the console as they are now? For example, if I define:
express = require('express');
server = express();
flash = require('connect-flash');
bodyParser = require('body-parser');
server.use(flash());
server.use(bodyParser.json());
server.use(bodyParser.urlencoded());
how do I see that Express now uses the flash middleware, and, separately, how do I see that Express now uses the middleware that consists of whatever function is exported by the connect-flash module? If one or both of these would not work for "whatever the bodyParser.json()/bodyParser.urlencoded() function is", is there another way to log that? As I said, it is not enough to simply console.log Express's use() function, or, if it is, I was not able to find the trick. There are a million ways in which a middleware function can be defined & use()d, so I don't expect any answer to work for all of them, but "as many as possible" would be nice.
Any answer should work for nested middleware, as well, as, for example, the Router and vhost middlewares can and usually do use() other middleware, and are in fact Express apps themselves.
Closest thing I know of is to run your app with the DEBUG environment variable set to express:router like this: DEBUG=express:router node server.js and watch the output as you use the app. Many of the functions you use as middleware are going to be anonymous since it is common to define them like this: app.get('/foo', function(req, res) {...}); thus express doesn't even have access to something as basic as a human-readable name for that route handler function.