Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js readline in debug-console in Visual Studio Code

I'm new to Visual Studio Code, Javascript and Node.js.

Coming from C# I want to debug something like this with breakpoints set in Debugging-console:

var name = Console.readline();
Console.Writeline(name);

It seems to be so simple, but I fail. What I found so far is, that after

npm install sget 

I can run app.js in integrated terminal and it will work interactively. But that ignores my breakpoints.

So, how can I work with readline-functionality and breakpoints set?

Thx -piccus

EDIT: Thank you Siam,

I already found the Code you referenced. After putting

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('What do you think of Node.js? ', (answer) => {
  // TODO: Log the answer in a database
  console.log(`Thank you for your valuable feedback: ${answer}`);

  rl.close();
});

into my app.js and pressing F5, the Debug-Control-Panel prompts:

node --debug-brk=38079 --nolazy app.js 
Debugger listening on [::]:38079
What do you think of Node.js? 

Unfortunately that is the end of Debugging. Whatever I fill into the commandline below that Debug-Control-Panel, the result is always

nicht verfügbar  

what probably stands for 'not available'. No further breakpoint is being reached.

Running that Code from seperate powershell will run as it should, but of Course does not care about Debugger.

piccus

like image 458
piccus Avatar asked Dec 12 '16 12:12

piccus


People also ask

How do I debug console in VS Code?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.


1 Answers

Add this line to you launch.json file:

"console": "externalTerminal" 
like image 137
Tyler Mecham Avatar answered Sep 21 '22 23:09

Tyler Mecham