Expressjs - Debugging

expressjs

How can we debug express application?

node app.js // or
DEBUG=myapp ./bin/www
DEBUG=myapp npm start

On Windows:

set DEBUG=myapp & node .\bin\www
set DEBUG=myapp & npm start

How can we debug Express?

Express uses the debug module internally to log information about route matches, middleware 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. It is turned off by default and can be conditionally turned on with the use an environment variable named DEBUG. To see all the internal logs used in Express, simply 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

How can we enable debugging for your application?

The app generated by the express command also uses the debug module and its debug namespace is scoped to the name of the application. 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 assignning a comma separated list of names, as shown below.

DEBUG=http,mail,express:* node index.js
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License