摘要:調(diào)試在內(nèi)部使用模塊來記錄有關(guān)路由匹配正在使用的中間件函數(shù)應(yīng)用程序模式以及請求響應(yīng)周期流的信息。在上,使用相應(yīng)的命令。生成的應(yīng)用程序命令生成的應(yīng)用程序也使用模塊,其的命名空間的范圍限定為應(yīng)用程序的名稱。
調(diào)試Express
Express在內(nèi)部使用debug模塊來記錄有關(guān)路由匹配、正在使用的中間件函數(shù)、應(yīng)用程序模式以及請求—響應(yīng)周期流的信息。
debug就像是console.log的增強版本,但與console.log不同,你不必在生產(chǎn)代碼中注釋掉debug日志,默認情況下,日志記錄處于關(guān)閉狀態(tài),可以使用DEBUG環(huán)境變量有條件地打開日志記錄。
要查看Express中使用的所有內(nèi)部日志,請在啟動應(yīng)用程序時將DEBUG環(huán)境變量設(shè)置為express:*。
$ DEBUG=express:* node index.js
在Windows上,使用相應(yīng)的命令。
> set DEBUG=express:* & node index.js
在express生成器生成的默認應(yīng)用程序上運行此命令將打印以下輸出:
$ 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 /+0ms express:router:layer new / +0ms express:router use / +0ms express:router:layer new / +0ms express:router use / +0ms express:router:layer new / +0ms
當對應(yīng)用程序發(fā)出請求時,你將看到Express代碼中指定的日志:
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
要僅從路由器實現(xiàn)中查看日志,請將DEBUG的值設(shè)置為express:router,同樣,要僅查看來自應(yīng)用程序?qū)崿F(xiàn)的日志,請將DEBUG的值設(shè)置為express:application,依此類推。
express生成的應(yīng)用程序express命令生成的應(yīng)用程序也使用debug模塊,其debug的命名空間的范圍限定為應(yīng)用程序的名稱。
例如,如果你使用$ express sample-app生成應(yīng)用程序,則可以使用以下命令啟用調(diào)試語句:
$ DEBUG=sample-app:* node ./bin/www
你可以通過分配以逗號分隔的名稱列表來指定多個調(diào)試命名空間:
$ DEBUG=http,mail,express:* node index.js
有關(guān)調(diào)試的更多信息,請參閱debug。
上一篇:錯誤處理 下一篇:在代理后面運行Express文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/100486.html
摘要:在微信項目的開發(fā)中,經(jīng)常需要對微信提供的接口進行調(diào)試,比如說錄音分享上傳圖像等接口,但是微信要求綁定安全域名才能使用其提供的一系列功能而在開發(fā)環(huán)境中使用或者本地無法完成域名的認證和綁定所以無法在本地調(diào)試。 在微信項目的開發(fā)中,經(jīng)常需要對微信jssdk提供的接口進行調(diào)試,比如說錄音, 分享 ,上傳圖像等接口,但是微信jssdk要求綁定安全域名才能使用其提供的一系列功能 , 而在開發(fā)環(huán)境中...
摘要:將如下代碼寫入到文件中,并在環(huán)境里執(zhí)行如圖雖然這兩個輸出看起來可能一樣,但系統(tǒng)實際上對它的處理方式有不同。如圖如果你沒有啟動調(diào)試日志,則不會看到任何這樣的日志輸出。 原文地址: https://www.twilio.com/blog/g...原文作者: DOMINIK KUNDEL 翻譯作者: icepy 翻譯出處: https://github.com/lightningm... ...
摘要:文檔基于的快速開放極簡主義的框架,是一個最小且靈活的應(yīng)用程序框架,為和移動應(yīng)用程序提供了一組強大的功能。借助無數(shù)的實用程序方法和中間件,你可以快速輕松地創(chuàng)建強大的。提供了一層輕薄的基本應(yīng)用程序功能,而不會隱藏你熟悉和喜愛的功能。 Express 文檔 基于Node.js的快速、開放、極簡主義的Web框架,Express是一個最小且靈活的Node.js Web應(yīng)用程序框架,為Web和移動...
摘要:在代理后面運行在代理后面運行應(yīng)用程序時,將通過使用應(yīng)用程序變量設(shè)置為下面列出的值之一。類型信任來自前置代理服務(wù)器的第跳作為客戶端。設(shè)置使用包實現(xiàn),有關(guān)更多信息,請參閱其文檔。 在代理后面運行Express 在代理后面運行Express應(yīng)用程序時,將(通過使用app.set())應(yīng)用程序變量trust proxy設(shè)置為下面列出的值之一。 雖然如果未設(shè)置應(yīng)用程序變量trust proxy,...
摘要:單元測試一個合格的庫應(yīng)該包含完整的單元測試。是的支持版,和是一樣的,它能夠直接運行為后綴的單元測試文件。在目錄下加入然后執(zhí)行即可看到單元測試結(jié)果。 這篇文章主要是講述如何使用 TypeScript 編寫一個完善,包含測試、文檔、持續(xù)集成的庫,涵蓋了編寫整個庫所需要的技術(shù)和工具,主要涵蓋: 項目目錄骨架 TypeScript 配置 使用 jest 單元測試 使用 vuepress 編寫...
閱讀 3054·2023-04-26 01:00
閱讀 953·2021-10-11 10:59
閱讀 3125·2019-08-30 11:18
閱讀 2821·2019-08-29 11:18
閱讀 1143·2019-08-28 18:28
閱讀 3151·2019-08-26 18:36
閱讀 2279·2019-08-23 18:16
閱讀 1231·2019-08-23 15:56