To write an array to file with Node.js, we call the writeFile
method.
For instance, we write
require("fs").writeFile("./my.json", JSON.stringify(myArray), (err) => {
if (err) {
console.error("error");
}
});
to call writeFile
with the file path and a stringified version of the myArray
array to write the content of myArray
into the my.json file.