Express JS pdf gets corrupted after download

I am using the following code to download a static pdf file

const downloadPDF = (req, res, next) => {
    const fileLoc = `output.pdf`;
    var filename = path.basename(fileLoc);
    var mimetype = mime.lookup(fileLoc);
    var stat = fs.statSync(fileLoc);
    res.setHeader('Content-Type', mimetype);
    res.setHeader('Content-Length', stat.size);
    res.setHeader('Content-disposition', 'attachment; filename=' + filename);
    return res.download(fileLoc);
}

the file becomes corrupted after download. What might be causing the issue ?