0

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.

2
  • What is the environment where you are running this code? Commented Dec 3, 2020 at 17:47
  • Firebase cloud functions Commented Dec 3, 2020 at 17:48

1 Answer 1

1

Firebase provides only a read-only file system. You can not write files on the system. You would have to use some kind of an Object storage like Amazon S3 or Firebase Cloud Storage.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.