How to start nodejs with custom parameters from vscode

Is there a way to start nodeJS with additional command line options?

like:

- harmony_generators
--harmony_arrow_functions

UPD:

workaround:

  • create a .bat (windows) file using

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

  • profit:)

+11
source share
4 answers

In the VSCode preview version, it is not yet possible to pass the node arguments from the launch.json file. But the workaround mentioned above works fine. I created an error on our side and make sure that it is fixed with the next version.

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, for example, run Node.js (v0.12) with ES6 support "runtimeArgs": ["--harmony"],

+14
source

In my case, I ran this command and parameter: node app.js read --title = "SomeTitle"

and decide that I used this:

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

and the output was as follows:

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

I really liked it.

The suggestion to use runtimeArgs does not work for me because it passed the "before" call to my app.js.

+2
source

With the current version 1.36.1, you can add arguments 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 application, you can capture Args:

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

Now you can start debugging Visual Studio code and see how the arguments are displayed

If you run the application from the console , it should look like this:

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

The result in both cases:

 my-url=http://192.168.1.24:8984/api/ port=3000 
+1
source

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

There is an args entry here that you can edit

-1
source

All Articles