30

Is there any way to start nodeJS with additional command line parameters?

like:

--harmony_generators
--harmony_arrow_functions

UPD:

workaround for now:

  1. create .bat (windows) file with:

    • {{path-to-node}}\node.exe --harmony_generators --harmony_arrow_functions %*
  2. add path to your .bat file as source of runtimeExecutable in .\settings\launch.json

  3. profit :)

leximus
  • 368
  • 1
  • 3
  • 10

4 Answers4

35

In the preview version of VSCode it is not yet possible to pass arguments to node from the launch.json. But the workaround mentioned above works fine. I have created a bug on our side and will make sure it’s fixed with the next release.

Andre Weinand, Visual Studio Code


Update:

The fix is in VSCode since v0.3 with this in .settings/launch.json:

"configurations": [
    {
        ...

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

        ...

So to e.g. run Node.js (v0.12) with ES6 support use "runtimeArgs": ["--harmony"],

jornh
  • 1,369
  • 13
  • 27
Andre Weinand
  • 1,907
  • 11
  • 8
  • this sadly is not working for me. i got node version v0.12.4 and vs code version 0.5.0. [Here](http://pastebin.com/w6KmWK9n) is my launch.json config. What am i missing? – JuHwon Jul 30 '15 at 09:12
  • 1
    What exactly is not working for you? The launch.json looks fine. – Andre Weinand Jul 30 '15 at 09:16
  • When the code hits the first generator fn i get the following error: `SyntaxError: Unexpected token *`. and btw it does not stop on entry. i am pressing the green play button in the debug pane with the `Launch app.js` config selected. – JuHwon Jul 30 '15 at 09:18
  • Bear in mind that you **MUST** pass the arguments with **no spaces** at all in the argument string. So this is valid: `"runtimeArgs": ["--harmony"]` , but this is **NOT** valid: `"runtimeArgs": [" --harmony "]` The second one will result in `Error: Cannot find module '/path/to/project/ --harmony '` – Lucio Mollinedo Jan 18 '17 at 17:00
10

In My case I was running this command and parameter: node app.js read --title="SomeTitle"

and to solve that i used this:

"args": [
            "read",
            "\--\--title\=='SomeTitle'"
        ]

and the output was this:

node --inspect=10398 --debug-brk app.js read --title='Title'

That suited me well.

The suggestion to use runtimeArgs don't worked for me because its passed "before" invoking my app.js.

cyberwillis
  • 101
  • 1
  • 4
4

With the current Versión 1.36.1 you can add args to your launch.json Example:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/index.js",
            "args":["my-url=http://192.168.1.24:8984/api/", "port=3000"]
        }
    ]
}

In your node app you can capture Args:

 process.argv.forEach(function (val, index, array) 
 {
   console.log(val);
 }  

Now you can run your Visual Studio Code debug and see how args are showed

If you run the App from console it should be like this:

node index.js my-url=http://192.168.1.24:8984/api/ port=3000

The output in both cases is:

my-url=http://192.168.1.24:8984/api/
port=3000
  • But if you need it before the path (like node -r esm index.js), then it does not work since it places arguments at the end – dortonway Aug 01 '21 at 09:01
1

Edit ./settings/launch.json (debug menu > gear icon)

There's an args entry you can edit

Simon
  • 390
  • 2
  • 9
  • the only way I can see for now is create .bat (windows) file and add manually all needed params and then define it in ./settings/launch.json as runtimeExecutable but that looks wired. – leximus Apr 30 '15 at 13:46