【问题标题】:VS Code node debug with command使用命令调试 VS Code 节点
【发布时间】:2017-08-29 16:36:28
【问题描述】:

我正在尝试使用 VS Code 运行一个简单的 CRUD 节点模块。

模块的简化版本如下所示:

const getAll = () => {
  // return all elements
}

const saveElement = element => {
  // takes an object and goes through it and saves it
}

const removeElement = id => {
  // deletes the element with the passed id or returns false
}

const readElement = id => {
  // returns the element from the data
}

我使用 yargs 来获取应用程序的参数,但我也使用命令来调用每个方法,就像这样

node app.js remove --id="123456789"

VS Code 中的launch.json 如下所示:

{
  "version": "0.2.0",
  "configurations": [       
    {
      "type": "node",
      "request": "launch",
      "name": "Test Remove",
      "program": "${workspaceRoot}/app.js",
      "args": [
        "--id='123456789'"
      ]
    }
  ]
}

我一直无法做的是将特定的removeaddlistread 命令添加到调试器中以检查这些方法,因为没有这些,应用程序仅使用参数和它返回一个我添加的日志,表明传递的命令未被识别。

我查看了 VS Code 文档,但没有找到与我正在尝试做的事情相关的任何内容。

【问题讨论】:

    标签: node.js debugging command visual-studio-code


    【解决方案1】:

    好的,知道了。其实很简单。只需在 args 数组中传递模块的特定命令即可。唯一需要注意的是,数组中的顺序必须与 CLI 中使用的顺序相同。所以如果这个想法是运行这个:

    node app.js remove --id="123456789"
    

    launch.json 对象应如下所示:

    {
      "version": "0.2.0",
      "configurations": [       
        {
          "type": "node",
          "request": "launch",
          "name": "Test Remove",
          "program": "${workspaceRoot}/app.js",
          "args": [
            "remove",
            "--id=123456789"
          ]
        }
      ]
    }
    

    更改 args 数组中的顺序将导致不希望的行为。

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2019-09-24
      • 2018-10-16
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      相关资源
      最近更新 更多