This is an archived forum post. The information may be outdated. Contact us if you have any questions.

node example saveToFile then send file to client

SomethingOn wrote on 2016-09-10:
Using this example code to save the PDF to file, mainly so I can set the filename, how would I think send it to the client? I'm using Express

client.convertFile('/local/file.html', pdf.saveToFile("file.pdf"));

does pdf.saveToFile() have a callback? Can I do something like this?

client.convertFile('/local/file.html', pdf.saveToFile("file.pdf", function(filePath){ res.download(filePath); });


Thanks,
Greg
support wrote on 2016-09-12:
Hello Greg,

saveToFile is just an example object:
var saveToFile = function(fname) {
    return {
        pdf: function(rstream) { 
            var wstream = fs.createWriteStream(fname);
            rstream.pipe(wstream);
        },
        error: function(errMessage, statusCode) { console.log("ERROR: " + errMessage); },
        end: function() {},
    };
}


Feel free to write your own version of saveToFile and implement the end() and error() properties.