title: How to download a .docx file in AngularJs controller from Node.js
body: <p>I've been looking in stackoverflow for some answer but I didn't succeed. </p>
  
  <p>I have a node.js method in routes which generates a .docx template from another template with docxtemplater library. </p>
  
  <p>I send a post from angularjs to my /api/generateReport with some data and I generate this .docx but I cant manage to send it. 
  It is not recommendable nor secure placing the file in /public dir but I can't download it if I place the file in /public dir and I provide the file path to AngularJs. </p>
  
  <p>I've read about blob and other stuff but I can't manage to download a .docx file. </p>
  
  <p>PS: I'm using $resource directive to handle api requests and I have set responseType to <code>arrayBuffer</code> </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>angular.module('MyApp')
    .factory('GenerateReport', function($http, $location,$resource, $rootScope, $alert, $window) {
  
         return $resource("/api/GenerateReport/:id",{}, {
              'query': {
                  method: 'GET',
                  isArray: false
              },
              responseType: 'arrayBuffer'
          });
  
    });</code></pre>
  </div>
  </div>
  </p>
  
  <p>I send the response this way.</p>
  
  <pre><code> var fileDocx = fs.readFileSync(__base + "/plantillaSalida.docx", "binary");
   res.send(fileDocx);
  </code></pre>
  
  <p>Response is received in angular controller: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>GenerateReport.save({
    projectExecution: $scope.projectExecution,
    auditingProject: $scope.auditingProject,
    participants: $scope.participants,
    exampleProjects: $scope.exampleProjects
    
    }, function(response) {
  
  /***What to to here??***/
  
      $mdToast.show(
      $mdToast.simple()
      .content('Informe generado')
      .position('bottom right left')
      .hideDelay(3000)
      );
    },
    function(error) {
      console.log("error");
      $mdToast.show(
      $mdToast.simple()
      .content('Error al general el informe')
      .position('bottom right left')
      .hideDelay(3000)
      );
    }
  );</code></pre>
  </div>
  </div>
  </p>