欲善其事,先利其器。nodejs除錯方法主要可以分為三類:
以乙個小demo(hello.js)為例對後面兩者做介紹:
console.log('server running at ');npm安裝node-inspector包:
npm install -g node-inspector
後台程序的方式啟動:
node-inspector
&
注意:這樣預設是以8080埠啟動,該埠經常被apache、nginx等常用web服務占用而報錯,錯誤內容如下:
➜ demo1 node inspector v0.12.8
cannot start the server at
0.0.0
.0:8080. error: listen eaddrinuse 0.0
.0.0:8080.
there is another process already listening at this address.
run `node-inspector --web-port=`
to use a different port.
[1] + 27585 done node-inspector
這時可以以–web-port=[port]的方式指定其他埠,方式為:
node-inspector
&--web-port
=8008
啟動node執行程式:
node--
debug
hello
.js
或者
node--
debug
-brk
hello
.js
瀏覽器視窗輸入如下
u will get hello.js in chrome window
–debug & –debug-brk的區別:
–debug會執行在請求檔案後立即用node執行該檔案;
–debug-brk會在檔案第一行設中斷,是否繼續執行需要依據使用者在chrome下的除錯命令;
chrome監聽埠8008請求後,通知node-inspector(5858埠:可通過–debug-port[port]進行配置),最終基於nodejs 提供的內建除錯模組進行除錯
NodeJS環境搭建
1.nodejs安裝 node依賴於ssl,通過sudo apt get install libssl dev安裝。node需要python壞境支援gyp generate your project 以完成原始碼管理,所以需要安裝python,預設linux下自帶的。git clone git cd...
NodeJs環境搭建
一 在windows平台上安裝node.js及npm模組管理 2 建立d nodejs目錄,並將node.exe儲存在這個目錄中。並將 d nodejs 加入系統環境變數path中,便於在任意位置執行node應用。3 將npm源 解壓到d npmjs目錄中。在命令提示符視窗中執行下面的操作,完成np...
搭建nodejs開發環境
windows環境1 安裝git 2 cmd進入安裝目錄執行 git clone 3 設定環境變數 可圖形ui set path d git nvmw path 4 重新進入終端cmd,安裝node 版本號可自定義 nvmw install 0.12.0 5 安裝iojs nvmw install ...