I'm trying to write a json file in node.js in the following way:
const fs = require('fs');
fs.writeFile('./keywords.json', JSON.stringify(keywords), function(err) {
if (err) throw err;
else console.log("success");
});
However I get the following error:
Error: EROFS: read-only file system, open './keywords.json'
So, I tried to open the file before writing it, in the following way:
fs.open('./keywords.json', 'w', function (err, file) {
if (err) throw err;
fs.writeFile('./keywords.json', JSON.stringify(keywords), function(err) {
if (err) throw err;
else console.log("success");
});
});
However the problem persists. How can i solve it? Thank you.