Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one feed stuff into a script's stdin while in the debugger interface?

I've run:

node debug f.js

And now I have a:

debug>

prompt. How can I toggle between the stuff I type into the terminal being interpreted as debug commands and it being fed to the script's stdin?

like image 508
user2958725 Avatar asked Nov 21 '13 16:11

user2958725


2 Answers

Debugging programs that read from stdin is vastly easier after the inclusion of inspector to node core in version 8+.

  1. Run the program via: node --inspect-brk f.js
  2. Open Chrome.
  3. Open chrome://inspect
  4. Click "Open dedicated DevTools for Node"

This will separate the debugger input out to a "remote" debugger allowing you to continue sending input into your program from command line.

I pulled the steps from this fantastic blog by Paul Irish

like image 66
Breedly Avatar answered Nov 13 '22 20:11

Breedly


In VSCode, you can add a new Debug Configuration file with the property "console" set to "integratedTerminal".

"configurations": [
{
  "type": "node",
  "request": "launch",
  "name": "Launch Program",
  "program": "${workspaceFolder}\\index.js",
  "console": "integratedTerminal"
}]

So now you can type into the terminal and debug your code.

like image 39
Richard Muñoz Avatar answered Nov 13 '22 21:11

Richard Muñoz