G
G
Galdar Turin2020-02-12 10:02:50
Node.js
Galdar Turin, 2020-02-12 10:02:50

How to stop a script and continue after typing a command in the console?

Good afternoon, there is a script in which a check is performed before the main task is performed, and I would like to stop the script at the verification stage if errors are found without complete completion, of course, the parameters that give an error will be indicated in the logs. After fixing them, you just need to press ENTER in the console or enter something, after which the script will continue its work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Galdar Turin, 2020-02-12
@Galdar

Thanks to all! Answer found...

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  prompt: 'OHAI> '
});

rl.prompt();

rl.on('line', (line) => {
  switch (line.trim()) {
    case 'hello':
      console.log('world!');
      break;
    default:
      console.log(`Say what? I might have heard '${line.trim()}'`);
      break;
  }
  rl.prompt();
}).on('close', () => {
  console.log('Have a great day!');
  process.exit(0);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question