title: How to handle user inputs synchronously in Node.js
body: <p>I know this may come across as a 'Noob Question', and I apologize in advance for asking something so simple. But I haven't been able to find much on this topic when searching online.</p>
  
  <p>I'm trying to write a command line app in Node.js, however I haven't been able to figure out how to handle user input synchronously. I tried using async/await, but those seemed to have no effect. Instead I moved to promises, however the following code errors out with: <code>TypeError: promise.resolve is not a function</code>. </p>
  
  <p>Reading the MDN it shows the Promise API as being <code>new Promise(resolutionFunc, rejectionFunc)</code>. With those functions being called on resolution and rejection respectively.</p>
  
  <p>I'm not quite sure what I'm doing wrong, but from what I understand it should only be executing the <code>.then()</code> after the previous promise is resolved. However that is not the case here:</p>
  
  <p>My Code:</p>
  
  <pre class="lang-js prettyprint-override"><code>const readline = require('readline');
  const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout,
      terminal: false
  });
  
  let numbs = [];
  
  function getInput(i) {
      let promise = new Promise((resolve) =&gt; {
          numbs[i] = resolve;
      }, (reject) =&gt; {
          // do nothing, shouldn't happen
      });
  
      rl.question(`Input #${i+1}: `, (input) =&gt; {
          promise.resolve(Number.parseInt(input));
      });
  
      return promise;
  }
  
  getInput(0)
  .then(getInput(1))
  .then(() =&gt; {
      console.log(numbs)
      /* 
          rest of the program using those 2 inputs 
      */
  })
  .catch((err) =&gt; {
      // do nothing, and exit
  });
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>$ node .\file.js
  Input #1: Input #1: 
  [path removed]/file.js:18
          promise.resolve(Number.parseInt(input));    
                  ^
  
  TypeError: promise.resolve is not a function
      at [path removed]/file.js:18:17
      at Interface._onLine (readline.js:335:5)
      at Interface._normalWrite (readline.js:482:12)
      at ReadStream.ondata (readline.js:194:10)
      at ReadStream.emit (events.js:315:20)
      at addChunk (_stream_readable.js:296:12)
      at readableAddChunk (_stream_readable.js:272:9)
      at ReadStream.Readable.push (_stream_readable.js:213:10)
      at TTY.onStreamRead (internal/stream_base_commons.js:186:23)
  </code></pre>