title: How to terminate npm inquirer prompt and return control to main menu/function
body: <p>I keep running into an issue with the inquirer npm package and cant find a solution anywhere. I am trying to allow a user to exit the inquirer prompt in a function at any point and return to the main menu. However, it seems this is causing multiple instances of the inquirer prompt to remain active causing this error: </p>
  
  <p>(node:9756) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added. Use emitter.setMaxListeners() to increase limit</p>
  
  <p>and also causing the inquirer prompt in the specific function to begin displaying the same prompt multiple times. I attached an image of the behavior after trying to use the function a several times. 
  <a href="https://i.stack.imgur.com/fB5tT.jpg" rel="noreferrer">Prompt Bug</a></p>
  
  <p>I have tried increasing the maximum number of event listeners which stopped the memory leak error but the inquirer prompt bug was unaffected.</p>
  
  <pre><code>inquirer.prompt([
          {
              name: 'itemid',
              type: 'input',
              message: 'Please enter the product id. (type "exit" to return to main menu)',
              validate(answer) {
  
                  //validates the id provided exists in the database. If exit is entered, returns to main().
                  var valid = false;
                  var exit = answer.toLowerCase();
                  id = parseInt(answer);
  
                  if (exit == "exit") {
                      return main();
                  }
  
                  for (var j = 0; j &lt; idCheckArray.length; j++) {
  
                      if (answer == idCheckArray[j]) {
  
                          valid = true;
  
                      } else {
                      }
                  }
  
                  if (valid === true &amp;&amp; exit != "exit") {
  
                      return (true);
  
                  } else {
  
                      return ("Item ID does not exist. Please enter a valid ID.");
                  }
              }
          },
  </code></pre>
  
  <p>I believe the cause is that by returning and calling main from within the inquirer validate function, inquirer does not call its build in end function and as a result every time this action is performed the event listeners created by inquirer are not removed.</p>
  
  <p>Any help with how to address this is greatly appreciated, Thanks.</p>