5

I am playing with the core modules of node js in VS code and i m unable to get it working with "readline" module.

I have the following code in js file.

const readline = require('readline');

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

rl.question('Is it working ?', function (answer) {
    console.log(answer);
});   

when i run it this is what i see in debug console

node --debug-brk=4868 --nolazy Core.js 
Debugger listening on port 4868
Is it working ?
No
not available

I am not sure what;s the issue here but it fails to log the answer to the console.

1 Answer 1

9

The Visual Studio Code documentation states that the 'Debug Console does not support programs that need to read input from the console'. To debug these programs you need to 'enable an external, native console by setting the attribute externalConsole to true in your launch configuration.' This documentation can be found here: Visual Studio Code Debugging See the section on Node Debugging.

When you add this setting to your launch configuration, VS Code will launch an external console that you can interact with.

Sign up to request clarification or add additional context in comments.

5 Comments

"externalConsole" has been deprecated. Instead use "console": "externalTerminal"
Or even better than launching cmd in another window use "console": "integratedConsole" in your launch.json and it will use the terminal window integrated into Visual Code instead of popping up an external window.
By default, Node.js debug sessions launch the target in the internal VS Code Debug Console. Since the Debug Console does not support programs that need to read input from the console, you can enable either an external terminal or use the VS Code Integrated Terminal by setting the console attribute in your launch configuration to externalTerminal or integratedTerminal respectively. Both options work.
Adding "console": "internalConsole" to your launch.json works as well. I think anything you specify that doesn't land in the Debug Console will do the trick
@JSWilson, For some reason when I set console to "integratedConsole" or externalTerminal, neither seems to produce any result whatsoever... i would expect to see integratedConsole show up in the terminal tab next to the debug console tab and the externalTerminal to open up a windows cmd terminal...but nothing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.