title: NodeJS NPM soap - how do I chain async methods without callbacks (ie use async or Promise)?
body: <p>I have successfully called a sequence of soap webservice methods using nodejs/javascript, but using callbacks... right now it looks something like this: </p>
  
  <pre><code>soap.createClient(wsdlUrl, function (err, soapClient) {
      console.log("soap.createClient();");
      if (err) {
          console.log("error", err);
      }
      soapClient.method1(soaprequest1, function (err, result, raw, headers) {
          if (err) {
              console.log("Security_Authenticate error", err);
          }
          soapClient.method2(soaprequest2, function (err, result, raw, headers) {
                  if (err) {
                      console.log("Air_MultiAvailability error", err);
                  }
                  //etc... 
          });
      });
  
  });
  </code></pre>
  
  <p>I'm trying to get to something cleaner using Promise or async, similar to this (based on the example in the docs here <a href="https://www.npmjs.com/package/soap" rel="nofollow noreferrer">https://www.npmjs.com/package/soap</a>) : </p>
  
  <pre><code>var soap = require('soap');
  
  soap.createClientAsync(wsdlURL)
      .then((client) =&gt; {
          return client.method1(soaprequest1);
      })
      .then((response) =&gt; {
          return client.method2(soaprequest2);
      });//... etc
  </code></pre>
  
  <p>My issue is that in the latter example, the soap client is no longer accessible after the first call and it typically returns a 'not defined' error... </p>
  
  <p>is there a 'clean' way of carrying an object through this kind of chaining to be used/accessible in subsequent calls ?  </p>