8

Is there a way to automatically restart the node debugger in VS Code when a source file changes like nodemon?

ermish
  • 1,160
  • 2
  • 13
  • 26

2 Answers2

9

You can use nodemon even for debugging. Below are the steps to configure in VS Code

  1. Open VSCode
  2. On top toolbar, go to Run > Add Configuration
  3. launch.json file will be created. Open that file and change as below
"configurations": [
        {
            "type": "pwa-node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}\\**app.js**",
            **"restart": true,
            "runtimeExecutable": "nodemon"**
        }
    ]

Make sure nodemon is installed globally. Also your entry point to server is app.js, if its different change it to that file name.

Mark
  • 143,421
  • 24
  • 428
  • 436
Emmad Zahid
  • 438
  • 6
  • 15
2

You cannot automatically restart the node debugger when the source file changes, but you could use a separate debugger that does monitor source file changes such as node-inspector.

node-inspector developed by StrongLoop also has a feature that allows you to edit your source code within the debugger while the server is running.

Install node-inspector

$ npm install -g node-inspector

Start the node-inspector server

$ node-inspector

Enable debug mode in your node process

$ node --debug your/node/program.js

Load the debugger UI

Open http://127.0.0.1:8080/?port=5858 in the Chrome browser

Steve Ermish
  • 113
  • 1
  • 9