[debug] How to set breakpoints project/lib/server/server.js ?

99 views
Skip to first unread message

Yoonje Choi

unread,
Mar 25, 2013, 11:24:08 PM3/25/13
to der...@googlegroups.com
It've been few days using Derby.
While debugging derby application, I can't find a way to set breakpoints in server-side codes.

An example project directory structure is this.

HelloWorld
 + lib
  |   + server
  |          |- index.js 
  |   + app 
  |          |- index.js
  |
  | ---- server.js

Using chrome developer's tool, It's easy to set breakpoints on any script files.
After derby app is fully loaded, web browser already recognize all scripts files and I can set breakpoints on every file I want.

For server-side debugging with node debug server.js, debugger doesn't know about /lib/server/index.js before fully executing.

HelloWorld/server.js contains 

if (process.env.NODE_ENV === 'production') {
  require('./src/bootstrap').listen(3000);
} else {
  require('derby').run(__dirname + '/src/bootstrap', 3000);
}


How can I set breakpoints in HelloWorld/lib/server/server.js? 



Juzer Ali

unread,
Mar 26, 2013, 4:20:03 AM3/26/13
to der...@googlegroups.com
Write `debugger;` anywhere in the code and run node with debugger, like so, `node debug server.js`.
This will set up a breakpoint. Read about node debugger.

Yoonje Choi

unread,
Mar 26, 2013, 4:39:09 AM3/26/13
to der...@googlegroups.com
Thanks, Ali. 

Why didn't I find it ? 
sorry to pollute groups. T.T

2013년 3월 26일 화요일 오후 5시 20분 3초 UTC+9, Juzer Ali 님의 말:

Schabse Laks

unread,
Mar 27, 2013, 9:42:28 PM3/27/13
to der...@googlegroups.com
This happens because require('derby').run() runs your code in a child process, which the debugger is not attached to.

If you call require('server').listen(), the debugger will work correctly, because everything will run in one process. 
AFAIK, this will break change listening, so you should only do it if a debugger is attached:

if (process.execArgv.indexOf("--debug") >= 0)
Reply all
Reply to author
Forward
0 new messages