express.js: how to download stream as a file?

My story is as follows: a user uploads a txt file to an express.js server, where the text file is transformed to a pdf file; the pdf file can be streamed back to the browser via request.pipe. I can get the stream on the user side, but how to let the browser download the stream as a pdf file?

If you already have the pdf as a readable stream, you can just do something like:

res.attachment('pdfname.pdf');
pdfstream.pipe(res);

Or if you have the pdf on disk, you can send it to the client simply with:

res.download('/path/to/file.pdf');

Or specify a custom filename that's presented to the browser:

res.download('/path/to/file.pdf', 'pdfname.pdf');