Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to read from console in node js using VS code

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.

like image 831
ace Avatar asked Jan 07 '23 10:01

ace


1 Answers

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.

like image 58
jaustrom Avatar answered Jan 19 '23 15:01

jaustrom