I'm trying to set route in my application to download a .json file when it is opened, however I can't quite figure out how res.sendFile works. When I send my file, for some reason the client receives a completely blank file with the correct name.
Here's my code:
fs.writeFile(path.join(__dirname, '../../public/send/file.json'), JSON.stringify(resultDict)); res.setHeader('Content-disposition', 'attachment; filename=file.json'); var options = { root: __dirname + '/../../public/send/', dotfiles: 'deny', headers: { 'x-timestamp': Date.now(), 'x-sent': true } }; res.sendFile('file.json', options, function(err){ if(err){ console.log(err); res.status(err.status).end(); } else{ console.log('Sent: ' + "file.json"); } }); Why is the sent file completely empty?