Код: Выделить всё
const downloadPayment = async (req, res) => {
const { id } = req.params;
if (!mongoose.Types.ObjectId.isValid(id)) {
return res.status(404).send('No payment with that id');
}
const payment = await Payment.findById(id);
if (!payment) {
return res.status(404).send('No payment with that id');
}
/*if (fs.existsSync(`./util/outputs/TestSözleşme.xlsx`)) {
console.log('Success');
}*/
res.download(`./util/outputs/${payment.title}.xlsx`, `${payment.title}.xlsx`);
};
Подробнее здесь: https://stackoverflow.com/questions/794 ... ile-exists
Мобильная версия