File not downloading express.js res.download
<p>I've generated/exported a <code>xlsx</code> file using <code>json2xlsx</code> npm module and to download that file I'm using <code>res.download(file)</code> functionality of of <code>express.js</code>.</p>

<p>Reference: <a href="https://stackoverflow.com/questions/7288814/download-a-file-from-nodejs-server-using-express">Download a file from NodeJS Server using Express</a></p>

<p>Following is my code:</p>

<pre><code>var fs = require("fs");
var json2xls = require('json2xls');

app.use(json2xls.middleware);

app.get('/export/:id', function (req, res) {
    var id = req.params.id;
    db.collection('provider').findOne({_id: mongojs.ObjectId(id)}, function (err, doc) {
        var jsonArr = {};
        var arr = jsonArr = doc;
        var xls = json2xls(arr);
        fs.writeFileSync('data.xlsx', xls, 'binary'); //file exported

        //Now I want to download that file
        res.setHeader('Content-disposition', 'attachment; filename=data.xlsx');
        res.setHeader('Content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        res.download(__dirname + '/public/data.xlsx', function (error) {
          console.log(error);
        });

        //res.json(doc);
    });
});
</code></pre>

<p>View html</p>

<pre><code>        &lt;div class="panel-body"&gt;

            &lt;div class="form-group" ng-repeat="(key,value) in providerList"  ng-if="!$first"&gt;                    
                    &lt;label&gt;{{key.replace("_", " ") | uppercase}}&lt;/label&gt;
                    &lt;input type="text" class="form-control" id="title" placeholder="Enter Title" ng-model="providerList[key]"&gt;                    
            &lt;/div&gt;

            &lt;div class="well well-lg text-center bg-gray"&gt;                                        
                &lt;button class="btn-lg btn-success" ng-click="export(id)"&gt;Export to Spreadsheet&lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
</code></pre>

<p>AngularJS controller code:</p>

<pre><code>$scope.export = function (id) {
            $http.put('/export/' + id, $scope.providerList).success(function (response) {
                 if (response) {
                    alert("File is successfully exported at: "+ response);
                }
            });
        };
</code></pre>

<p>Error: <code>{ [Error: Request aborted] code: 'ECONNABORTED' }</code></p>

<p><strong>Updated Error</strong></p>

<p><a href="https://i.stack.imgur.com/Z6vLg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z6vLg.png" alt="enter image description here"></a></p>

<p>Any help would be appreciated.</p>