How can I append to a file using fs.write()
?
Using fs.write on the same files overwrites the content:
var fs = require('fs');
try {
fs.write("file.txt", "Hello World", 'w');
fs.write("file.txt", "Hello World", 'w');
} catch(e) {
console.log(e);
}
Use append mode
a
instead of [over]write modew
in the fs.write call.I inferred this based on the
pythonCopen()
fopen
documentation; Glad it worked, other file modes may work but were not tested by me.