title: Save outlook Email attachment using ews-javascript-api npm in node JS
body: <p>I am trying with below solution using ews-javascript-api npm Node JS. but this solution is not working, not able to download attachment (Excel File) to specific path. please provide me proper solution for the same.</p>
  
  <pre><code>var ews = require('ews-javascript-api')
  var ExchangeService = ews.ExchangeService;
  var service = new ExchangeService(ews.ExchangeVersion.Exchange2010);
  service.Credentials = new ews.ExchangeCredentials("userName", "Password");
  service.Url = new ews.Uri("https://outlook.office365.com/Ews/Exchange.asmx");
  
  var view = new ews.ItemView(1);
  
  var items = service.FindItems(ews.WellKnownFolderName.Inbox, "hasattachment:true",new ews.ItemView(1)  );
  items.then(function (response) {
      "use strict";
      var count = 0;
  
      for (var item of response.Items) {
  
          let email = response.Items[0];
  
            email.Load(new ews.PropertySet(ews.BasePropertySet.IdOnly, [ews.ItemSchema.Attachments,ews.ItemSchema.HasAttachments])).then(() =&gt; {           
                let file = email.Attachments.Items[0];
          file.Load().then(() =&gt; {
               var fs = require('fs');
                fs.writeFile("test.txt", file.Base64Content.toString(), function (err) {
                    if (err) {
                        return console.log(err);
                    }
  
                   console.log("The file was saved!");
                }); 
  
               console.log(file.Base64Content);
  
            }, (error) =&gt; {
              if (error) {
             console.log(error)
              }
         });
       }, function (error) {
             console.log("Email");
             if (error) {
             console.log(error)
           }
         });
  
           count = count + 1;
       }
       console.log(count);
   }
   );
  </code></pre>