Using NodeJS, I am setting a code to save a string in a file where it can be retrieved from later. Instead of the string being saved, I receive an error message saying that the file system is read-only. This seems strange because in tutorial examples, the file is created if it doesn’t exist, and the data is written. So, I’d like to understand how my desired outcome could be achieved.
My code is:
const fs = require('fs');
async function saveTestFile(testFile) {
try {
fs.writeFileSync("./test_file.txt", testFile, "utf8");
console.log("Saved file details = ", testFile);
} catch (error) {
console.error("Error saving test file:", error);
}
}
The error message received is:
Error saving refresh token: Error: EROFS: read-only file system, open './test_file.txt'
What is the cause of this error and can it be overcome please? It seems strange that it doesn’t simply work.
With thanks.