Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug node in VSCode with sudo in mac?

I want to debug node like this in terminal:

$sudo node app

But, in vscode, I don't know where I can configure it.

This is my launch.json. Nothing has helped,

launch.json

like image 211
Kaiser.Wang Avatar asked Nov 20 '15 02:11

Kaiser.Wang


2 Answers

In order to run the command as sudo you have to launch VS code under sudo. Here's how you do that ...

  1. Install "code" as a shell command if you haven't already by opening visual studio code regularly then opening the command palette (press F1) and type "Shell Command". This will bring up "Install 'code' command in PATH". More on that here: https://code.visualstudio.com/Docs/editor/setup#_mac-os-x
  2. Run "sudo code" in your terminal, and you should see that when you run "node app" it'll be running under sudo.
like image 156
Erik Elkins Avatar answered Sep 22 '22 17:09

Erik Elkins


First, create attach process config:

    {
        "name": "Attach to Process",
        "type": "node",
        "request": "attach",
        "port": 9222
    }

and run it.

Second, run node to debug like this.

sudo node --inspect=9222 app.js
like image 42
Paul Han Avatar answered Sep 23 '22 17:09

Paul Han