调试
Express 在内部使用 debug 模块来记录有关路由匹配、正在使用的中间件函数、应用程序模式以及请求-响应周期的流程的信息。
debug
就像console.log
的增强版,但与console.log
不同的是,您不必在生产代码中注释掉debug
日志。日志记录默认关闭,可以使用DEBUG
环境变量有条件地打开。
要查看 Express 中使用的所有内部日志,请在启动应用程序时将 DEBUG
环境变量设置为 express:*
。
$ DEBUG=express:* node index.js
在 Windows 上,使用相应的命令。
> set DEBUG=express:* & node index.js
在 express 生成器 生成的默认应用程序上运行此命令会打印以下输出:
$ DEBUG=express:* node ./bin/www
express:router:route new / +0ms
express:router:layer new / +1ms
express:router:route get / +1ms
express:router:layer new / +0ms
express:router:route new / +1ms
express:router:layer new / +0ms
express:router:route get / +0ms
express:router:layer new / +0ms
express:application compile etag weak +1ms
express:application compile query parser extended +0ms
express:application compile trust proxy false +0ms
express:application booting in development mode +1ms
express:router use / query +0ms
express:router:layer new / +0ms
express:router use / expressInit +0ms
express:router:layer new / +0ms
express:router use / favicon +1ms
express:router:layer new / +0ms
express:router use / logger +0ms
express:router:layer new / +0ms
express:router use / jsonParser +0ms
express:router:layer new / +1ms
express:router use / urlencodedParser +0ms
express:router:layer new / +0ms
express:router use / cookieParser +0ms
express:router:layer new / +0ms
express:router use / stylus +90ms
express:router:layer new / +0ms
express:router use / serveStatic +0ms
express:router:layer new / +0ms
express:router use / router +0ms
express:router:layer new / +1ms
express:router use /users router +0ms
express:router:layer new /users +0ms
express:router use / <anonymous> +0ms
express:router:layer new / +0ms
express:router use / <anonymous> +0ms
express:router:layer new / +0ms
express:router use / <anonymous> +0ms
express:router:layer new / +0ms
UaqaXTmxFrQC2Gz2FF/Eth8LA+vCn7TqTRyK5sDFL2e0XFqEi/5YrQM9bJO6t/A0oWnAcz0Agyjuv0wDs/DRWD3o/2pT9+z81Ye3TdtduDLKW1EgGuZdLAF/Al+kIwgS
express:router dispatching GET / +4h
express:router query : / +2ms
express:router expressInit : / +0ms
express:router favicon : / +0ms
express:router logger : / +1ms
express:router jsonParser : / +0ms
express:router urlencodedParser : / +1ms
express:router cookieParser : / +0ms
express:router stylus : / +0ms
express:router serveStatic : / +2ms
express:router router : / +2ms
express:router dispatching GET / +1ms
express:view lookup "index.pug" +338ms
express:view stat "/projects/example/views/index.pug" +0ms
express:view render "/projects/example/views/index.pug" +1ms
J3yYm3OGEHmXFTOgFcMS7k52aYW+duAUmwSGE9zwRZQ2R9ymfhl/T0+DeoklP//Uucvlfa7/pcgrPzbljEpfXDdLBCuPrwy8WRvLFuYs2fHDr0+oTBha+jE/pPufgCNEZUr5I0eaO9XZn0rlzOu9PZuYfJnvaNqEjhoIi/noZEVxdSPrTgJzxv1dVP5Uwqa2wYAssjZVc6Qpo/ZYSfBr/K4ZOIkuiia0p1jrOhSRgAMBGKyvUTk6D86bSPvdWbAYHfB8808x4jT1TMHv2roU7N4vAuFTnhwQhWisEsjnI7vNWKsYE/tXzFUUNPDrpm3TNJ9mXSk5flY9Tl3oStmZwucrkhS43L/R7WFcHj7zNx0=
express 生成的应用程序
vZRD8KL9YIvhPIZPiCGLv93b5nz9HpIxnPjsZ69/SEz5v4r/Jb0pfl9pen1MySCofIZx0xtsBu6xT3OPBbiK4v8P6QWjC9PHE2zPnAPuR/VlQd7UQuzws8qy1RLvjkcIueGuupQBS/4K9ZavLVIygm+MQC3yrvFACGfqLc5ijYQaWn8N5W9HYP4Vf2tPtIDF7FBwN0UB1srE47Jogj5dnA==
1zKJY1WSReWXbg/4/MKhj6YjV4NG9VCpnLM63Sbx1VAUy75Qc31VPBTL7BGqDusSSUONL6zjZGSkK9g4qr15CfPwtGzf14EFiBP+DX9BpWtIslM+49IdxQELOj+d64NXebnohKRK9qxWbo1hg92nK0j/mvIbY9uKDwBhpnXDJi6ngqBFIKw7Ixz727N4bwlj
$ DEBUG=sample-app:* node ./bin/www
7tSq9ONN6wnlgzQRYIbjACkpn0Tj4cAVcmPXuuX47opWk21fribbYiUm6Ra9jRZge2og4l38Ol+Qw9jb30mj2p7cWhqEG6BbP/ITCWXgU8PfeDplFJsm8eKUAbsyLyHh
$ DEBUG=http,mail,express:* node index.js
高级选项
KgUB+9Lq0znArsEm31aRFVtBG7sJVz6TB+o3nYcWNWoBGT7GQp9sYl2FiXUZxg7bNsNzAPwECEcXYCZArwur54qPp7jt/mPvT4Tl8PdNI87FWlDS+qrR+FYpJ0ZGWiT6
名称 | 目的 |
---|---|
DEBUG | 启用/禁用特定的调试命名空间。 |
DEBUG_COLORS | 是否在调试输出中使用颜色。 |
DEBUG_DEPTH | 对象检查深度。 |
DEBUG_FD | 要将调试输出写入的文件描述符。 |
DEBUG_SHOW_HIDDEN | 显示检查对象的隐藏属性。 |
9Tn5AN9GszRX1UWoqN7Cs6jKsRPspCKa0veF+jR8CxZS5Xs6oD1PYpsB6LOif87WbgcbGELtEUxVjC/SxRChOvSl/281pPAdi5s3Cs9GX10xx/sFFkpx7j1k4/dt3dpV1I6jQlLAhW1wnDEXxmf7CDEaEjv+dAZiw+7CM2t86IUxsrlhxe74idSJz3ocyXKzwEXGdkRQ7UfSwlF3zTrm0MpNGnMcEw2SMbRZN9ga7WXCgaVFnHVhVDIq1nqj64l//454pjG7ec5cv/QWCkbAxhFVSAK+Zd5EEZvgotah4183ZFzZrWIHcBFxkdGnxGPxwfzg3Whcwn3XYrjFNS6bqO04aTaEp37mbVU/UFYl5LC0UFttRUCqeVu52OrIKg6v1EBHknvzLvZTluEvKBKcDw==
资源
mBw/fB5DKmgN9GPwbs/yKs6t9z/IYXcx1qe2EbM3VDHtxrh9fb4pylgkpcpZWKAn7ZW0VaNlFbozS0ZGAlnwDG8Ng+upI5yXERs8b5B6g3md9YITVY0JjPqOST44izFgbpy+eJ4kmDOaHtfvmbGnog==