如何使用vscode中的自定义参数启动nodejs

lex*_*mus 13 visual-studio-code

有没有办法用额外的命令行参数启动nodeJS?

喜欢:

--harmony_generators
--harmony_arrow_functions

UPD:

现在解决方法:

  1. 使用以下命令创建.bat(windows)文件:

    • {{path-to-node}} \node.exe --harmony_generators --harmony_arrow_functions%*
  2. 路径添加到您的.BAT文件的源runtimeExecutable\设置\ launch.json

  3. 利润:)

And*_*and 16

在VSCode的预览版本中,尚无法从launch.json向节点传递参数.但上面提到的解决方法运行正常.我已经在我们这边创建了一个bug,并确保它在下一个版本中得到修复.

Visual Studio Code的Andre Weinand


更新:

自从v0.3以来,修复程序在VSCode中,其中包含.settings/launch.json:

"configurations": [
    {
        ...

        // Optional arguments passed to the runtime executable.
        "runtimeArgs": [],

        ...
Run Code Online (Sandbox Code Playgroud)

因此,例如运行Node.js(v0.12)并使用ES6支持 "runtimeArgs": ["--harmony"],


小智 6

使用当前的 Versi\xc3\xb3n 1.36.1,您可以将 args 添加到launch.json \n示例:

\n\n
{\n    "version": "0.2.0",\n    "configurations": [\n        {\n            "type": "node",\n            "request": "launch",\n            "name": "Launch Program",\n            "program": "${workspaceFolder}/index.js",\n            "args":["my-url=http://192.168.1.24:8984/api/", "port=3000"]\n        }\n    ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

在您的节点应用程序中,您可以捕获参数:

\n\n
 process.argv.forEach(function (val, index, array) \n {\n   console.log(val);\n }  \n
Run Code Online (Sandbox Code Playgroud)\n\n

现在您可以运行Visual Studio Code 调试并查看参数如何显示

\n\n

如果您从控制台运行应用程序,它应该是这样的:

\n\n
node index.js my-url=http://192.168.1.24:8984/api/ port=3000\n
Run Code Online (Sandbox Code Playgroud)\n\n

两种情况的输出都是:

\n\n
my-url=http://192.168.1.24:8984/api/\nport=3000\n
Run Code Online (Sandbox Code Playgroud)\n


cyb*_*lis 5

就我而言,我正在运行此命令和参数: node app.js read --title="SomeTitle"

为了解决这个问题,我使用了这个:

"args": [
            "read",
            "\--\--title\=='SomeTitle'"
        ]
Run Code Online (Sandbox Code Playgroud)

输出是这样的:

节点 --inspect=10398 --debug-brk app.js 读取 --title='Title'

那很适合我。

使用 runtimeArgs 的建议对我不起作用,因为它在调用我的 app.js 之前通过了“之前”。

  • `runtimeArgs` 用于节点参数,`args` 用于脚本参数。 (3认同)