To write a line into a .txt file with Node.js, we call the appendFile
function.
For instance, we write
const fs = require("fs");
fs.appendFile("log.txt", "new data", (err) => {
if (err) {
// append failed
} else {
// done
}
});
to call appendFile
to append 'new data'
to log.txt.
And we get the error from err
if there’re any errors.