Debugging Express

Express uses the debug module
internally to log information about route matches, middleware functions that are in use, application mode,
and the flow of the request-response cycle.

debug is like an augmented version of console.log, but unlike console.log, you don’t have to
comment out debug logs in production code. Logging is turned off by default and can be conditionally turned on by using the DEBUG environment variable.

To see all the internal logs used in Express, set the DEBUG environment variable to
express:* when launching your app.

$ DEBUG=express:* node index.js

On Windows, use the corresponding command.

> set DEBUG=express:* & node index.js

Running this command on the default app generated by the express generator prints the following output:

To see the logs only from the router implementation set the value of DEBUG to express:router. Likewise, to see logs only from the application implementation set the value of DEBUG to express:application, and so on.

Applications generated by express

An application generated by the express command also uses the debug module and its debug namespace is scoped to the name of the application.

For example, if you generated the app with $ express sample-app, you can enable the debug statements with the following command:

$ DEBUG=sample-app:* node ./bin/www

You can specify more than one debug namespace by assigning a comma-separated list of names: