Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error while running javascript program that takes input from user on visual studio code

enter image description here

const prompt = require("prompt-sync")();

var fname = prompt("Enter your first name: ");
var lname = prompt("Enter your last name: ");

console.log("Your full name is", fname, lname); 

I tried running the above code of javascript on vscode and the error popping up is

node:internal/fs/utils:350
    throw err;
    ^

Error: ENXIO: no such device or address, open '/dev/tty'

I have installed nodejs and javascript ES6 intellisense. I also ran the npm install prompt-sync command on the terminal before running the program.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Make sure you ran the program in a terminal (with npm start or node yourScript.js). The error essentially means there is no terminal to take the input from.

If you run it through VS Code as a task then the output will be captured and displayed to you, but there is no interactive terminal attached that would take input for the program. That’s why the program fails trying to open the terminal device.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading