title: Multiple menus with Node.js
body: <p>How can I create multiple menus with Node.js. I already found documentation at <a href="https://nodejs.org/api/process.html#process_process_stdin" rel="nofollow">https://nodejs.org/api/process.html#process_process_stdin</a> and used most of it in my example.</p>
  
  <p>The problem is that in the next menu <code>showSub</code> the main menu stayed as listener. When I try something like <code>process.stdin.pause</code> or <code>process.stdin.end</code> it will exit my code.</p>
  
  <p>Side note: I don't want to use any dependencies. Thanks for helping!</p>
  
  <p>Here an example:</p>
  
  <pre><code>// Main
  function showMain() {
      console.log(
          '1 = Show sub' + '\n' +
          '2 = Show other sub blabla...'  + '\n' +
          '3 = Exit'  + '\n\n' +
          'Choose number, then press ENTER:'
          );
      process.stdin.setEncoding('utf8');
      process.stdin.on('readable', checkMenu);
  
      function checkMenu() {
          var input = process.stdin.read();
          if(input !== null) {
              switch(input.trim()) {
                  case '1': showSub(); break;
                  case '2': showOtherSubBlaBla; break;
                  case '3': process.exit(); break;
                  default: showMain();
              }
          }
      }
  }
  
  // Sub
  function showSub() {
      // process.stdin.pause(); Do I need this somewhere? It should not exit my code
      console.log(
          '1 = Do something bla bla' + '\n' +
          '2 = Go back to main'  + '\n\n' +
          'Choose number, then press ENTER:'
          );
      process.stdin.setEncoding('utf8');
      process.stdin.on('readable', checkMenu);
  
      function checkMenu() {
          var input = process.stdin.read();
          if(input !== null) {
              switch(input.trim()) {
                  case '1': doSomethingBlaBla(); break;
                  case '2': showMain; break;
                  default: showSub();
              }
          }
      }
  }
  
  showMain();
  </code></pre>