(For Node 8 and later)
Node.js has a built-in debugger. Normally you can turn on the debugger in two ways:
Start your Node.js app or script with the --inspect
or --inspect-brk
switch. For example:
$ node.js --inspect index.js
(Note: --inspect-brk
breaks before user code starts)
If for some reason you cannot start your Node.js app or script with the --inspect
switch, you can still instruct the Node.js process to start listening for debugging messages by signalling it with SIGUSR1 (on Linux and OS X). For Node 8 and later it will activate the Inspector API, same as the --inspect switch
$ kill -sigusr1 23485
(Note: you need to replace 23485 with your own Node.js process ID)
With the debugger turned on, you can open the Google Chrome browser, and type in the address bar chrome://inspect
Then you should see an entry listed under "Remote Target". Go ahead and click "inspect".
Now you can set breakpoints and start debugging your code.
Reference:
- https://nodejs.org/en/docs/guides/debugging-getting-started/
- Related issue on stackoverflow:
Chrome Devtools Dedicated Node.js Inspector not stopping at breakpoints
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…