ExpressJS - Debugging



Express uses the Debug module to internally log information about route matching, middleware functions, application mode, etc.

Install debug module

E:\Dev\hello-world>npm install debug
added 10 packages, removed 1 package, changed 2 packages, and audited 143 packages in 3s

20 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

To see all internal logs used in Express, set the DEBUG environment variable to Express:* when starting the app −

E:\Dev\hello-world>set DEBUG=express:* 

E:\Dev\hello-world>nodemon index.js

The following output will be displayed.

Debug log

These logs are very helpful when a component of your app is not functioning right. This verbose output might be a little overwhelming. You can also restrict the DEBUG variable to specific area to be logged. For example, if you wish to restrict the logger to application and router, you can use the following code.

DEBUG = express:application,express:router node index.js

Debug is turned off by default and is automatically turned on in production environment. Debug can also be extended to meet your needs, you can read more about it at its npm page.

Advertisements