- CoffeeScript Application Development Cookbook
- Mike Hatfield
- 301字
- 2021-07-23 19:35:52
Debugging CoffeeScript using Node Inspector
Source maps and Chrome's developer tools can help troubleshoot our CoffeeScript that is destined for the Web. In this recipe, we will demonstrate how to debug CoffeeScript that is designed to run on the server.
Getting ready
Begin by installing the Node Inspector NPM module with the following command:
npm install -g node-inspector
How to do it...
To use Node Inspector, we will use the coffee
command to compile the CoffeeScript code we wish to debug and generate the source map.
In our example, we will use the following simple source code in a file named counting.coffee
:
for i in [1..10] if i % 2 is 0 console.log "#{i} is even!" else console.log "#{i} is odd!"
To use Node Inspector, we will compile our file and use the source map parameter with the following command:
coffee -c -m counting.coffee
Next, we will launch Node Inspector with the following command:
node-debug counting.js
How it works...
When we run Node Inspector, it does two things.
First, it launches the Node debugger. This is a debugging service that allows us to step through code, hit line breaks, and evaluate variables. This is a built-in service that comes with Node. Second, it launches an HTTP handler and opens a browser that allows us to use Chrome's built-in debugging tools to use break points, step over and into code, and evaluate variables.
Node Inspector works well using source maps. This allows us to see our native CoffeeScript code and is an effective tool to debug server-side code.
The following screenshot displays our Chrome window with an active break point. In the local variables tool window on the right-hand side, you can see that the current value of i
is 2
:

The highlighted line in the preceding screenshot depicts the log message.
- 計算機網絡
- Visual Studio 2012 Cookbook
- 自己動手實現Lua:虛擬機、編譯器和標準庫
- 青少年美育趣味課堂:XMind思維導圖制作
- Visual C
- Python機器學習算法與實戰
- Python算法從菜鳥到達人
- Python Web數據分析可視化:基于Django框架的開發實戰
- 西門子S7-200 SMART PLC編程從入門到實踐
- PHP 7從零基礎到項目實戰
- 零基礎看圖學ScratchJr:少兒趣味編程(全彩大字版)
- Python Programming for Arduino
- Java核心編程
- Learning D3.js 5 Mapping(Second Edition)
- 透視C#核心技術:系統架構及移動端開發