Debugging Express
To see all the internal logs used in Express, set the DEBUG environment variable to
express:* when launching your app.
$DEBUG=express:*nodeindex.jsOn Windows, use the corresponding command.
> $env:DEBUG = "express:*"; nodeindex.jsRunning this command on the default app generated by the express generator prints the following output:
$DEBUG=express:*node./bin/wwwexpress:router:routenew/+0msexpress:router:layernew/+1msexpress:router:routeget/+1msexpress:router:layernew/+0msexpress:router:routenew/+1msexpress:router:layernew/+0msexpress:router:routeget/+0msexpress:router:layernew/+0msexpress:applicationcompileetagweak+1msexpress:applicationcompilequeryparserextended+0msexpress:applicationcompiletrustproxyfalse+0msexpress:applicationbootingindevelopmentmode+1msexpress:routeruse/query+0msexpress:router:layernew/+0msexpress:routeruse/expressInit+0msexpress:router:layernew/+0msexpress:routeruse/favicon+1msexpress:router:layernew/+0msexpress:routeruse/logger+0msexpress:router:layernew/+0msexpress:routeruse/jsonParser+0msexpress:router:layernew/+1msexpress:routeruse/urlencodedParser+0msexpress:router:layernew/+0msexpress:routeruse/cookieParser+0msexpress:router:layernew/+0msexpress:routeruse/stylus+90msexpress:router:layernew/+0msexpress:routeruse/serveStatic+0msexpress:router:layernew/+0msexpress:routeruse/router+0msexpress:router:layernew/+1msexpress:routeruse/usersrouter+0msexpress:router:layernew/users+0msexpress:routeruse/ <anonymous> +0msexpress:router:layernew/+0msexpress:routeruse/ <anonymous> +0msexpress:router:layernew/+0msexpress:routeruse/ <anonymous> +0msexpress:router:layernew/+0msWhen a request is then made to the app, you will see the logs specified in the Express code:
express:routerdispatchingGET/+4hexpress:routerquery:/+2msexpress:routerexpressInit:/+0msexpress:routerfavicon:/+0msexpress:routerlogger:/+1msexpress:routerjsonParser:/+0msexpress:routerurlencodedParser:/+1msexpress:routercookieParser:/+0msexpress:routerstylus:/+0msexpress:routerserveStatic:/+2msexpress:routerrouter:/+2msexpress:routerdispatchingGET/+1msexpress:viewlookup"index.pug"+338msexpress:viewstat"/projects/example/views/index.pug"+0msexpress:viewrender"/projects/example/views/index.pug"+1msTo 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 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/wwwYou can specify more than one debug namespace by assigning a comma-separated list of names:
$DEBUG=http,mail,express:*nodeindex.jsAdvanced options
When running through Node.js, you can set a few environment variables that will change the behavior of the debug logging:
| Name | Purpose |
|---|---|
DEBUG | Enables/disables specific debugging namespaces. |
DEBUG_COLORS | Whether or not to use colors in the debug output. |
DEBUG_DEPTH | Object inspection depth. |
DEBUG_FD | File descriptor to write debug output to. |
DEBUG_SHOW_HIDDEN | Shows hidden properties on inspected objects. |
Note
The environment variables beginning with DEBUG_ end up being converted into an Options object
that gets used with %o/%O formatters. See the Node.js documentation for
util.inspect() for the complete
list.