0

I have a node.js application with express which write html files, and sometimes update them. Is it a bad practice or breaking practice to write and read from the same file at the same time?

fs.writeFile(file_location,data)
res.sendFile(file_location) 

The goal is to send the previously generated file before it updates.

Is it a bad practice to write the html data twice at the same time?

Eran Shmuel
  • 149
  • 2
  • 15

1 Answers1

0

This should solve your purpose. But, I would not prefer this approach. res.sendFile closes the connection and not the execution of the program and so the line next to it works.

res.sendFile(file_location)
fs.writeFileSync(file_location,data)
Sathya
  • 431
  • 3
  • 7