How to debug a nodemon project in VSCode

后端 未结 6 1745
醉酒成梦
醉酒成梦 2021-02-04 01:19

I have a NodeJs project and I run it using nodemon,
I wish to run it in debug mode for development tasks, but I am unable to do so.

I found that I\'ll need to ad

6条回答
  •  长发绾君心
    2021-02-04 02:02

    Change package.json to

    "scripts": {
        "dev": "node app.js",
        "debug": "nodemon --inspect app.js"
    }
    

    --inspect is for versions >= 6.3. --legacy or --auto for older versions

    And launch.json to:

    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Node: Nodemon",
            "processId": "${command:PickProcess}",
            "restart": true,
            "protocol": "inspector"
        }
    ]
    

    the restart flag is the key here.

    Start app via new debug script

    npm run debug

    • In Debug view, select the Node: Nodemon configuration and press play or F5
    • Choose the process started above

    See more: vscode nodemon recipe

提交回复
热议问题