Express.js kawaii logo
Skip to content
Edit on GitHub

Debugging Express

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

Terminal window
$DEBUG=express:*nodeindex.js

On Windows, use the corresponding command.

Terminal window
> $env:DEBUG = "express:*"; nodeindex.js

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

Terminal window
$DEBUG=express:*node./bin/www
express:router:routenew/+0ms
express:router:layernew/+1ms
express:router:routeget/+1ms
express:router:layernew/+0ms
express:router:routenew/+1ms
express:router:layernew/+0ms
express:router:routeget/+0ms
express:router:layernew/+0ms
express:applicationcompileetagweak+1ms
express:applicationcompilequeryparserextended+0ms
express:applicationcompiletrustproxyfalse+0ms
express:applicationbootingindevelopmentmode+1ms
express:routeruse/query+0ms
express:router:layernew/+0ms
express:routeruse/expressInit+0ms
express:router:layernew/+0ms
express:routeruse/favicon+1ms
express:router:layernew/+0ms
express:routeruse/logger+0ms
express:router:layernew/+0ms
express:routeruse/jsonParser+0ms
express:router:layernew/+1ms
express:routeruse/urlencodedParser+0ms
express:router:layernew/+0ms
express:routeruse/cookieParser+0ms
express:router:layernew/+0ms
express:routeruse/stylus+90ms
express:router:layernew/+0ms
express:routeruse/serveStatic+0ms
express:router:layernew/+0ms
express:routeruse/router+0ms
express:router:layernew/+1ms
express:routeruse/usersrouter+0ms
express:router:layernew/users+0ms
express:routeruse/ <anonymous> +0ms
express:router:layernew/+0ms
express:routeruse/ <anonymous> +0ms
express:router:layernew/+0ms
express:routeruse/ <anonymous> +0ms
express:router:layernew/+0ms

When a request is then made to the app, you will see the logs specified in the Express code:

Terminal window
express:routerdispatchingGET/+4h
express:routerquery:/+2ms
express:routerexpressInit:/+0ms
express:routerfavicon:/+0ms
express:routerlogger:/+1ms
express:routerjsonParser:/+0ms
express:routerurlencodedParser:/+1ms
express:routercookieParser:/+0ms
express:routerstylus:/+0ms
express:routerserveStatic:/+2ms
express:routerrouter:/+2ms
express:routerdispatchingGET/+1ms
express:viewlookup"index.pug"+338ms
express:viewstat"/projects/example/views/index.pug"+0ms
express:viewrender"/projects/example/views/index.pug"+1ms

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 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:

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

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

Terminal window
$DEBUG=http,mail,express:*nodeindex.js

Advanced options

When running through Node.js, you can set a few environment variables that will change the behavior of the debug logging:

NamePurpose
DEBUGEnables/disables specific debugging namespaces.
DEBUG_COLORSWhether or not to use colors in the debug output.
DEBUG_DEPTHObject inspection depth.
DEBUG_FDFile descriptor to write debug output to.
DEBUG_SHOW_HIDDENShows 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.

AltStyle によって変換されたページ (->オリジナル) /