K
K
Konstantin2017-08-04 22:26:48
JavaScript
Konstantin, 2017-08-04 22:26:48

How to write a value to a variable from the keyboard?

Good afternoon. Tell me, how can I write a value to a variable, which can then be used in the program, entered from the keyboard?
I tried to use the readline module, but did not fully understand how to do it. I don't understand exactly how the readline.clouse() method works. After using it, the execution of the script ends.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2017-08-04
@raydmend

The readline documentation has a simple example:

const readline = require('readline');

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

rl.question('What do you think of Node.js? ', (answer) => {
  // здесь что-то делайте с полученной строкой answer
  console.log(`Thank you for your valuable feedback: ${answer}`);

  rl.close();
});

What exactly is not clear in the example?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question