How do you debug a Node.js server running with Chrome/WebKit as the remote debugger?

后端 未结 4 1502
清歌不尽
清歌不尽 2021-02-01 06:21

If you have your Node running

node --debug server.js

This gives me a port number xxxx, should I use this port number when starting Chrome?

4条回答
  •  有刺的猬
    2021-02-01 06:33

    Recent versions of Node (> v6.3.0) and Chrome now allow you to use the Chrome Developer Tools to debug a Node.JS process without having to install anything else. Just pass --inspect to node:

    $ node --inspect script.js
    
    Debugger listening on port 9229.
    Warning: This is an experimental feature and could change at any time.
    To start debugging, open the following URL in Chrome:
        chrome-devtools://SOME-URL-HERE
    

    Just open that URL in Chrome, and you're good to go.

    If you need to pause your script immediately after Node starts, you can also pass --debug-brk in the same command.

提交回复
热议问题