To write in a text file without overwriting with Node. js, we can use the appendFile method. to call fs. appendFile with the path of the file to write to and the content to write into the file respectively.
To overwrite a file, to write new content into a file, we have to open our file in “w” mode, which is the write mode. It will delete the existing content from a file first; then, we can write new content and save it.
The final way of preventing overriding is by using the final keyword in your method. The final keyword puts a stop to being an inheritance. Hence, if a method is made final it will be considered final implementation and no other class can override the behavior.
Instead of "w"
use "a"
(append) mode with open
function:
with open("games.txt", "a") as text_file:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With