使用Chrome浏览器调试nodejs代码 转载:https://blog.csdn.net/zhouzying/article/details/98960721

今天给大家分享一下在chrome浏览器上调试nodejs代码的步骤。下面是操作:

第一步,在命令行输入调试命令:

node --inspect-brk app.js

这是调试命令的一些参数(来自官网的):

Command-line options

The following table lists the impact of various runtime flags on debugging:

Flag Meaning

--inspect

Enable inspector agent

Listen on default address and port (127.0.0.1:9229)

--inspect=[host:port]

Enable inspector agent

Bind to address or hostname host (default: 127.0.0.1)

Listen on port port (default: 9229)

--inspect-brk

Enable inspector agent

Listen on default address and port (127.0.0.1:9229)

Break before user code starts

--inspect-brk=[host:port]

Enable inspector agent

Bind to address or hostname host (default: 127.0.0.1)

Listen on port port (default: 9229)

Break before user code starts

node inspectscript.js

Spawn child process to run user's script under --inspect flag; and use main process to run CLI debugger.

node inspect --port=xxxx script.js

Spawn child process to run user's script under --inspect flag; and use main process to run CLI debugger.

Listen on port port (default: 9229)

--inspect-brk参数后面也能指定端口,未指定就使用默认的9229端口。

第二步,打开chrome开始调试:

1.在地址栏中输入:chrome://inspect

2.出现如下图所示的情况:

这时候点击, 绿色字体那块,open dedicated DevTools for node.

3.于是就会出现调试页面:

于是我们就可以开始调试node代码了。

————————————————

版权声明:本文为CSDN博主「Jasonzhiying」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/zhouzying/article/details/98960721