V
V
Vitaly2016-11-16 17:29:41
Node.js
Vitaly, 2016-11-16 17:29:41

How to make a dynamic console line in node.js?

For example, such as in npm during the installation of packages. Those. erase extra characters behind you to replace with a new line.
I will also be grateful if you tell me how to make a printed line by default. Here's what I mean: when the script asks for parameters for the config, I want to substitute the default values, which can then be erased or corrected.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aves, 2016-11-16
@vitali1995

https://nodejs.org/api/readline.html

const readline = require('readline');

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

rl.question('node.js это круто? ', (answer) => {
  switch (answer.toLowerCase()) {
    case 'да':
    case 'yes':
      console.log(answer, '- это правильный ответ');
      break;
    default:
      console.log(answer, '- ошибочное мнение');
  }
  rl.close();
});

rl.write('Да');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question