(四)、node.js對於程式的調試

來源:互聯網
上載者:User

標籤:node.js對於程式的調試

Node.js 支援命令列下的單步調試。下面是一個簡單的程式: 

var a = 1;var b = ‘world‘; var c = function(x) {  console.log(‘hello ‘ + x + a);};c(b);

在命令列下執行 node debug debug.js,將會啟動調試工具:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/59/A9/wKioL1TbEvKT-l4_AABy-WpWoXk843.jpg" title="Image.png" alt="wKioL1TbEvKT-l4_AABy-WpWoXk843.jpg" />

Node.js 調試命令

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/59/A9/wKioL1TbEwbAMoZ8AAMluxiknd0919.jpg" title="Image1.png" alt="wKioL1TbEwbAMoZ8AAMluxiknd0919.jpg" />

輸入 n 表示下一行

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/59/AD/wKiom1TbEirSeY19AACbCOWCNfw417.jpg" title="Image2.png" alt="wKiom1TbEirSeY19AACbCOWCNfw417.jpg" />

輸入 sb(‘debug.js‘, 4) 表示在函數的第四行設定斷點

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/59/A9/wKioL1TbEy_RnJYSAADhX5temIU231.jpg" title="Image3.png" alt="wKioL1TbEy_RnJYSAADhX5temIU231.jpg" />


使用elipse調試

在使用 Eclipse 之前,首先在 http://www.eclipse.org/downloads/ 取得一份 Eclipse。 
啟動 Eclipse,選擇功能表列中 Help→Install New Software...,此時會開啟一個安裝對話方塊,
點擊右邊的按鈕Add...,接下來會開啟一個標題為Add Repository的對話方塊,在 Location 中輸
入 http://chromedevtools.googlecode.com/svn/update/dev/,Name 中輸入 Chrome Developer,然後點擊OK按鈕。

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/59/AD/wKiom1TbEmeSLAZ4AAJ8tuSgiOk432.jpg" title="Image4.png" alt="wKiom1TbEmeSLAZ4AAJ8tuSgiOk432.jpg" />

然後在Work with後面的組合框中選擇剛剛添加的Chrome Developer,等待片刻,在列表
中選中Google Chrome Developer Tools,然後點擊Next,

Google Chrome Developer Tools
這時 Eclipse 會計算出所需安裝的包和依賴,點擊Next

閱讀 License,選取I accept the terms of the license agreements,點擊Next,

接下來 Eclipse 會開始安裝

安裝完成以後 Eclipse 會提示重新啟動以應用程式更新,點擊Restart Now,V8 調試工具就安
裝完成了。


2. 使用 Eclipse 調試 Node.js 程式
用 Eclipse 開啟一個 Node.js 代碼,選擇Debug perspective進入調試視圖,3-15所示。
點擊工具列中 Debug 表徵圖右邊的向下三角形,選擇Debug Configurations... 。在
配置視窗的左側找到Standalone V8 VM,點擊左上方的New表徵圖,會產生一個新的配置。在
配置中填寫好Name,如NodeDebug,以及Host和Port。點擊Apply應用配置。

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/59/AD/wKiom1TbEp7zDUKgAAIctIHRdVk314.jpg" title="Image5.png" alt="wKiom1TbEp7zDUKgAAIctIHRdVk314.jpg" />

配置調試

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/59/AD/wKiom1TbErSxO0-9AADEpA-hQn4145.jpg" style="float:none;" title="Image6.png" alt="wKiom1TbErSxO0-9AADEpA-hQn4145.jpg" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/59/A9/wKioL1TbE6mj3u6kAAHxwnxTflI512.jpg" style="float:none;" title="Image7.png" alt="wKioL1TbE6mj3u6kAAHxwnxTflI512.jpg" />

配置 Standalone V8 VM
接下來,通過 node --debug-brk=5858 debug.js 命令啟動要調試指令碼的調試服
務器,然後在 Eclipse 的工具列中點擊調試按鈕,即可啟動調試

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/59/AD/wKiom1TbEwvyxSPLAALpIyGM7e8035.jpg" title="Image8.png" alt="wKiom1TbEwvyxSPLAALpIyGM7e8035.jpg" />

本文出自 “my dream fly on the sky” 部落格,請務必保留此出處http://7915791.blog.51cto.com/7905791/1613746

(四)、node.js對於程式的調試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.