Search code examples
node.jsfirebasegoogle-cloud-functionsfile-writing

EROFS error when executing a File Write function in Firebase


I have hosted my website using Firebase. However, I am stuck.

My idea is to create a user page. When the user clicks "create my page" I want a new page to be created which will hold details about the user. The user can share the URL of the new page to his friends and his friends should be able to see his data.

I tried using the fs module in node js in order to write an additional page using cloud functions. This method of reading data, writing it, and then rendering it back to the user works perfectly fine when it is run on the localhost. However, after deploying the website, when the function is executed, it throws an error message stating " EROFS: read-only file system".

Please suggest ways to deal with this error.


Solution

  • Node's fs module is only for writing the local filesystem. Since you are using Firebase Functions, the only writable part of the FS is /tmp as mentioned here. If you want to write to Cloud Storage instead since you need to persist these files, you're going to have to use the Cloud Storage SDK (or the Admin SDK, which wraps the Cloud Storage SDK).