To write to a CSV in Node.js, we call writeFile
.
For instance, we write
let dataToWrite;
const fs = require("fs");
fs.writeFile("form-tracking/formList.csv", dataToWrite, "utf8", (err) => {
if (err) {
console.log("Some error occured");
} else {
console.log("It's saved!");
}
});
to call writeFile
to write the dataToWrite
CSV string to the form-tracking/formList.csv file.
If there’re any errors then, err
in the callback would be set.