title: Avoid callback hell and organising Node.js code
body: <p>i am trying to orgainse my code and wanted to create separte function for every .then(),some how i am unable to do,and my code break</p>
  
  <p>please help me how to make things working</p>
  
  <pre><code>module.exports = function () {
     return new Promise((resolve, reject) =&gt; {
     try {
       const settings = blob();
  
      var {
      someObject
       } = JSON.parse(requestBody);
    var var1,var2,var3
  
    let somePromises = [];
  
    someObject.forEach((p) =&gt; {
      p.somepro = 'anything';
    });
  
    Promise.all(somePromises)
      .then((res) =&gt; {
        //replace cart item info
        res.forEach((r) =&gt; {
          someObject.forEach((so) =&gt; {
                so.info = ''
            });
          });
        });
      return require('/file1')(); // api call 1
      })
      .then((res) =&gt; {
        var2 = resp.something // local variable create above var2
        return require('/file2')(); // api call 2
      })
       .then((res) =&gt; {
        var3 = resp.something // local variable create above var3
        return require('/file2')(); // api call 3
      })
      .then((r) =&gt; {
        // some other maniuplation
      })
      .then(() =&gt; {
        // some calulation based on above responses and local variable 
        // assigned
        resolve({
          someObject,
          var1,
          var2
        });
      });
  } catch (e) {
    reject(e);
  }
   });
  };
  </code></pre>
  
  <p>i am trying to make the code organise and create separate function for every promise but not getting and confused how can i create this flow in an organised and best practise ways</p>