Problem and Solutions
How do I send a variable from the server as a downloadable text file with a specific file name in nods.js ?
By M.K. Verma · 2 May 2022

With fs.writeFileSync you do actually create a file on the server. Instead, use
res.set("Content-Disposition", "attachment; filename=" + filename);
res.end(filedata);