var fs = require('fs'); var page=this; var result = page.evaluate(function() { var out; $.ajax({ 'async' : false, 'url' : 'fullurltodownload.csv', 'success' : function(data, status, xhr) { out = data; } }); return out; }); fs.write('mydownloadedfile.csv', result);