admin管理员组

文章数量:1330591

I would like, from the Electron index.html file, to modify a config file present in the.asar of my application. In my case I need to change, if necessary, my application database config in order to work.

I understood that .asar is in readOnly and I wanted to know if there is a way to modify this config file from electron without changing its position in my application?

I see the extraResources option but I did not understand how its work.

It's also important that the config file stay in myapp/config folder.

Thanks for your help :)

I would like, from the Electron index.html file, to modify a config file present in the.asar of my application. In my case I need to change, if necessary, my application database config in order to work.

I understood that .asar is in readOnly and I wanted to know if there is a way to modify this config file from electron without changing its position in my application?

I see the extraResources option but I did not understand how its work.

It's also important that the config file stay in myapp/config folder.

Thanks for your help :)

Share Improve this question asked Jun 11, 2018 at 15:08 SynoSyno 411 silver badge6 bronze badges 1
  • I am also having similar issue. I want a file to be editable. Were you able to find solution to your problem? – vaasu varma Commented Nov 11, 2020 at 13:04
Add a ment  | 

5 Answers 5

Reset to default 2

What build tool do you use? If you are using electron builder, you can check out asarUnpack in configuration file here or extraFiles here

I was able to edit the read-only file by first changing the file permissions programmatically and then editing it.

fs.chmod(filename, 0666, (error) => {
        console.log('Changed file permissions');
    });

   ...
    code to modify file
   ...

asar is in readonly

as you mentioned asar intended to be readonly package. For runtime-changing config, you should place it outside of asar and change values accordingly.

To manage settings you should use a node package that's specifically designed for this, like electron-settings or preferences.

As an alternative one may manually read an write config files that you place in the platform's native config directory.


Mutable application settings shouldn't be stored in the asar file. If it's required to replace a file in an asar archive for any other reason, use the the asar program to extract the entire archive to a temporary directory, replace the file(s) you want, then create a new asar file, replacing the original asar file.

  • To unpack .asar files -> asar extract electron.asar app

  • modify as per your needs

  • To pack .asar files -> asar pack . electron.asar

本文标签: javascriptElectron modify file store in asarStack Overflow