1.开启远程调试
在服务器终端中输入
node --inspect=0.0.0.0:9229 rundebug.js
Debugger listening on ws://0.0.0.0:9229/670e55ef-6d1f-444f-9178-674d4c639565
For help, see: https://nodejs.org/en/docs/inspector
2.本地vscode配置远程调试
vscode中打开launch.json增加配置
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Remote",
"address": "192.168.129.164",//服务器的地址
"port": 9229,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/home/dev/Desktop/nodeExpress",//服务器上的代码根目录
"skipFiles": [
"/**"
]
}
]
}
本地代码需要和远程代码保持一致,不然可能出现断点不生效的问题