블로그 이미지
윤영식
Full Stacker, Application Architecter, KnowHow Dispenser and Bike Rider

Publication

Category

Recent Post

2012. 12. 10. 15:42 NodeJS/Concept

node명령으로 자바스크립트 코드를 수행할 때 콘솔상에서 debugging을 할 수 있다. 


  • debugger 키워드를 코드에 끼워 넣는다 : breakpoint 역할을 한다 
  • cont, c : 계속 진행 
  • next, n : step next
  • step, s : step in
  • out,   o : step out
  • pause  : 실행 멈춤 
  • 상세명령들

> 예제 코드 (debuggerTest.js)
x = 5;
setTimeout(function () {
  debugger;
  console.log("world");
}, 1000);
console.log("hello");



> 디버깅 수행 : node debug <수행 자바스크립트 파일명>

D:\Framework\Node.js> node debug debuggerTest

< debugger listening on port 5858

connecting... ok

debug> cont

< hello

break in D:\Framework\Node.js\debuggerTest.js:3

  1 x = 5;

  2 setTimeout(function () {

  3   debugger;

  4   console.log("world");

  5 }, 1000);

debug> next

break in D:\Framework\Node.js\debuggerTest.js:4

  2 setTimeout(function () {

  3   debugger;

  4   console.log("world");

  5 }, 1000);

  6 console.log("hello");

debug> cont

< world

program terminated


hello을 찍고 debugger가 있는 곳에서 멈추면 next step으로 이동하면 console 객체로 가고 cont하면 수행을 다시 하여 world 문자가 찍힌다. 수행되는 process를 command line에서 추적해 보고자 할 경우 사용하면 좋겠다. 


'NodeJS > Concept' 카테고리의 다른 글

[EJS] 사용하기  (0) 2012.12.15
[Node.js] Global Objects  (0) 2012.12.10
[Node.js] File I/O 사용하기  (0) 2012.12.10
[Node.js] EventEmitter 에 대하여  (0) 2012.12.10
[Express] Express Framework 사용하기  (0) 2012.10.30
posted by 윤영식