console.log
;
debugger
node inspect index.js(入口文件)
;
注:在Node >= 6.3的版本可使用inspect方式,低版本使用debug方式,即node debug index.js(入口文件)
node --inspect index.js(入口文件)
node --inspect-brk index.js(入口文件)
chrome://inspect
,找到对应的Remote Target,如图:
--inspect
: 启动debug模式,并监听9229端口(默认端口);
--inspect-brk
: 启动debug模式,并监听9229端口(默认端口),并在开始处进行断点;
注:版本支持
Node.js 6.3+ Chrome 55+
.vscode
文件夹下的
launch.json
进行配置对应的调试方式,若没有就进行建立;
注:Node >= 6.3 使用inspect模式,低版本使用debug模式
launch
,一种是
attach
;
launch
是启动程序并进行调试;
attach
是调试某个已启动的线程;
注意:这种方式就不须要启动debug模式也能进行选择调试,VSCode会自动开启对应的调试端口;若是想看是否自动开启端口,MAC端用户可使用netstat -anL 查看
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"port": 9229
}
复制代码
inspect
协议默认端口为9229);
注:此方式须要项目以debug模式进行启动;
Since it is a bit laborious to repeatedly find the process ID and enter it in the launch configuration, Node debug supports a command variablePickProcess
that binds to the process picker (from above) and that lets you conveniently pick the process from a list of Node.js processes.
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"processId": "${command:PickProcess}"
}复制代码
注:此方式也是不须要以debug模式也能调试,VSCode会开启对应的调试端口
待续...html