How to write within the app

I have an Electron build where I have put my app in Electron.app/Contents/Resources/app

Everything works fine. When I try to write a file (for instance with fs.writeFileSync) within the app root iteself (Electron.app/Contents/Resources/app directory) I get the following error:

Uncaught Error: EACCESS: permission denied

I made sure that the directory is writable. I can write everywhere else (for instance in /tmp). Since I need the app to modify some files of the app itself (for update reasons), what’s wrong in what I’m trying to do? How to overwrite app files?

Most OS’s do not let you write to the app bundle. Mac OS among others also has sandboxes
so you can’t write anywhere. tmp is typically allowed since it’s specifically a temp file.

Electron has some specific directories allowed for apps, including user content.

I’ve been writing to app.getPath('userData') on Windows and macOS with no problems.

Writing into the .app bundle is not recommended.