Answer the question
In order to leave comments, you need to log in
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
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();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question