-2

Pls. can anyone help on this?

enter image description here

What is that two dots under require? and its not showing output result?

enter image description here

When trying to type in the output terminal, its not typing anything?

Thanks.

I am trying this code today and i could not give the user input.

1
  • 3
    Welcome to Stack Overflow! Relevant code and error messages need to be included in your question as text, not as pictures of text. Just linking to screen shots makes it more difficult for people to help you. To learn more about this community and how we can help you, please start with the tour and read How to Ask and its linked resources. Commented Jan 11, 2023 at 13:02

1 Answer 1

0

When you bring your cursor to dots you can see message like this:

File is a CommonJS module; it may be converted to an ES module.

You can either use Quick Fix or change your import like this:

import readline from "readline";

Also, do not forget to add "type": "module", to your package.json

Edit

In your code you imported readline as rLine but while you are creating interface you used it as readline.createInterface() you should update your code like this:

import readline from "readline";

var rl = readline.createInterface(process.stdin, process.stdout);

rl.question("What is your name?\n", (answer) => {
  console.log(answer);
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I tried that one and the code is running. But may i know why i could not give the input from the input terminal?
I edited my answer and added the working code. Take a look at it and let me know if it helped.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.