简体   繁体   English

如何用mac中的sudo调试VSCode中的节点?

[英]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. 但是,在vscode中,我不知道我可以在哪里配置它。

This is my launch.json. 这是我的launch.json。 Nothing has helped, 什么都没有帮助,

launch.json launch.json

In order to run the command as sudo you have to launch VS code under sudo. 要以sudo身份运行命令,您必须在sudo下启动VS代码。 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". 如果尚未定期打开visual studio代码然后打开命令调色板(按F1键)并键入“Shell Command”,则将“code”作为shell命令安装。 This will bring up "Install 'code' command in PATH". 这将在PATH中显示“安装'代码'命令”。 More on that here: https://code.visualstudio.com/Docs/editor/setup#_mac-os-x 更多相关内容: 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. 在您的终端中运行“sudo code”,您应该看到当您运行“node app”时它将在sudo下运行。

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

I have the same issue. 我有同样的问题。 I'm trying to debug an app that connects to port 443 on a Mac. 我正在尝试调试连接到Mac上的端口443的应用程序。 In order to get around the problem I've been using I added the following to my package.json under scripts. 为了解决我一直在使用的问题,我将以下内容添加到我的package.json脚本下。

"debug": "sudo devtool server.js",

With this you can debug, just not as nice since you are using the chrome debugger verses the one in vscode. 有了这个,你可以调试,因为你使用的是chrome调试器和vscode中的调试器,因此不太好。 You will need to have devtool from chrome installed for this to work. 你需要安装chrome的devtool才能工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM