title: I still get the pyramid of doom when using promises, what am I doing wrong?
body: <p>I am using the <a href="https://github.com/sboudrias/Inquirer.js" rel="noreferrer">Inquirer</a> library with Node.js and I still get the pyramid of doom when using promises, what am I doing wrong?</p>
  
  <p>Just FYI the inquirer library API is basically:</p>
  
  <pre><code>inquirer.prompt([
  question1,
  question2,
  question3,
  ...
  questionX
  ]).then(function(answers){});
  </code></pre>
  
  <p>where answers is a hash, with keys that represent each question. Nothing really out of the ordinary here.</p>
  
  <p>Anyway, using the API, I always get <code>getAnswersToPrompts().then(function(answers){})</code> and it seems more convenient to keep nesting the promises inside the previous one...like so:</p>
  
  <pre><code>function run (rootDir) {
  
    return watchHelper().then(function (answers) {
  
      return chooseDirs({
  
        allowDirs: answers.allow,
        originalRootDir: rootDir,
        onlyOneFile: false
  
      }).then(function (pathsToRun) {
  
        assert(pathsToRun.length &gt; 0, ' You need to select at least one path.');
  
        return getOptions(availableOptionsForPlainNode).then(function (answers) {
  
          const selectedOpts = answers[ 'command-line-options' ];
  
          return localOrGlobal().then(function (answers) {
  
            const sumanExec = answers.localOrGlobal;
  
            console.log(' =&gt; ', colors.magenta.bold([ '$', sumanExec, '--watch', pathsToRun, selectedOpts ].join(' ')));
  
  
          });
  
        });
  
      });
  
    }).catch(rejectionHandler);
  
  }
  </code></pre>
  
  <p>I could possibly do this instead:</p>
  
  <pre><code>function run(){
  
    return makePromise()
      .then(fn1(data1))
      .then(fn2(data2))
      .then(fn3(data3))
  
  }
  </code></pre>
  
  <p>where fn1,fn2,fn3 look like:</p>
  
  <pre><code>function fnX(data){
  
     return function(answers){
  
        return promise(data);
  
     }
  }
  </code></pre>
  
  <p>but this just makes things more complicated to understand AFAICT</p>
  
  <p>Just be as clear as possible, I definitely need the result of the previous promise, but sometimes I need the result from the promise prior to that or even the result prior to that.</p>
  
  <p>Nesting the functions allows the data I need to be in scope, thanks to closures etc.</p>