Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code redirect input on debug

My application is reading from stdin:

var input = process.stdin.read();

Is it possible to configure Visual Studio Code to redirect input on debug?

So it is be equal to this command line:

node app.js < input.txt

This configuration is not working, and debug is not starting.

{
  "name": "Launch",
  "type": "node",
  "program": "app.js",
  "stopOnEntry": false,
  "args": [
    "<",
    "input.txt"
  ]
}
like image 793
Dizzy Avatar asked Sep 30 '15 10:09

Dizzy


People also ask

How do I move to the next Debug point in Visual Studio?

You can press F5 while debugging to jump to next breakpoint and F10 to jump line by line.

How do I make my VS code go to the next line?

I usually use ctrl + n/p to go to next/previous line in VSCode.

How do I enable auto link in VSCode?

You enable auto attach by running Debug: Toggle Auto Attach command from the Command Palette, and once activated you can toggle auto attach from the Status Bar as well.


1 Answers

The args array is generally for Node.js startup and V8 engine runtime flags.

  --no-deprecation
  --throw-deprecation
  --trace-deprecation
  --v8-options
  --max-stack-size=val
  --icu-data-dir=dir

  --enable-ssl2
  --enable-ssl3

Type node --v8-options at the command line to see the full list of V8 runtime flags.

I'd recommend you start your application with the debug flag from the command line so you can direct it to take stdin and then attach the debugger to your running process.

> node --debug app.js
Debugger listening on port 5858

You can have multiple configurations in your launch.json file. Add or modify one to be your "Attach" debug configuration. For attaching, "address" and "port" must be specified (please note that "address" must be set to "localhost" since remote debugging is not yet supported). Port should be the one that the debug startup process returned above.

Enter image description here

Once your application is running on the port specified, you can change the debug target in the dropdown next to the play/run icon.

Enter image description here

like image 149
Ryan Joy Avatar answered Sep 18 '22 01:09

Ryan Joy