ermish
ermish

Reputation: 1270

VS Code automatically restart debugger on file save like nodemon

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

Upvotes: 10

Views: 7678

Answers (2)

Emmad Zahid
Emmad Zahid

Reputation: 508

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.

Upvotes: 13

Steve Ermish
Steve Ermish

Reputation: 113

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

Upvotes: 2

Related Questions