Why is Node fs.writeFile() method successful, but an empty file is then sent to the browser?
writeFile
is asynchronous.either use it as:
fs.writeFile('helloworld.txt', 'helloworld', function () { res.download('helloworld.txt');});
or use writeFileSync
https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback
Try to find out if your code has
process.exit()
for some reason. If you do, comment out this one and you will be good to go. My version is v8.6.0.
See also: node - fs.writeFile creates a blank file