启动 app

pm2 start --node-args="--inspect=9229" app.js

vscode 调试 pm2( node.js )_vscode

--inspect=9229 设置调试端口为 9229

vscode里添加 launch.json

vscode 调试 pm2( node.js )_调试_02

环境选择选 Node.js 即可

{
            "address": "127.0.0.1",
            "localRoot": "${workspaceFolder}",
            "name": "Attach to Remote",
            "port": 9229,
            "remoteRoot": "/home/git/test-sequelize/",
            "request": "attach",
            "restart": true,
            "skipFiles": [
                "<node_internals>/**"
            ],
            "type": "pwa-node"
        }

vscode 调试 pm2( node.js )_调试_03

点击启动 debug

出现下面浮框启动成功

vscode 调试 pm2( node.js )_pm2_04

打开:http://localhost:3000/

vscode 调试 pm2( node.js )_pm2_05

打开调试控制台

vscode 调试 pm2( node.js )_node.js_06

点开 右侧 app.js 文件可以打断点进行调试