I have such a problem. I need to create a pair of functions for saving and loading matrices to and from text files.
Here is a part of my code, but I'm not sure if it's right or not.
const fs = require('fs');
function saveToTextFile(matrix) {
fs.writeFile("./new.txt", matrix, (err) => {
if(err){
console.log(err);
}
else {
console.log("saved to textfile1");
}
});
console.log("next");
}
How are your matrices defined? Would a simple
JSON.stringify(matrix);
and
JSON.parse(matrixJsonStringFromFile);
already do the trick?