Proper way to save user parameters for future use


Hi there !

I began to write my first app using Electron recently so my question might sounds a bit “stupid”.

As many other apps, I need to save user settings in order to use them each time the app is launched. The thing is, I have no idea what would be the best way to handle that situation.

Do I need to use a cookie ? Do I need to write a file and load it each time the app is launched ?

Thanks for taking the time to help me :smile:


Yes, this is the approach that would probably be best to take. Take a look at Atom’s Config class for an example of how it can work.


So I think what Atom does is that it’s creating a hidden .atom folder in the user home folder to store the data. Should I need to do the same thing ? Or is it possible to write a file inside the app folder ?


It’s up to you. It’s your application :smile:

Most OS won’t allow you to write to the application folder without elevated permissions though (depending on where your app gets installed) so it might be best to plan to store the configuration in whatever location the OS has set aside for such things.


It’s a bit weird, but I have seen apps saving their config state in a single environment variable, which then gets read from again at application start.
Obviously, this is quite limiting, but if you only have a handful of values to store, it’s one way.


Thanks guys ! :smile:
I think I’ll go for the file preferences then, it seems to be the better way to do that.
I’ll take a look at how Atom handles that in its code :blush:


I went to another “good practice” question.

I’ll need to store “sensible” data in this settings file (like login and password). I don’t want to write them as they are in the settings file for obvious security reasons. Do anyone have a recommendation regarding this scenario ? I guess I’ll have to go for an encryption method but I’ve never did it using javascript.

Thanks !


See here for links to topics discussing storing sensitive information:


Don’t forget that you can use any package on npm with Electron. You could for example use configstore to store non-sensitive info.


That’s a great piece of advice ! Thanks !
I’m really new to all node.js / npm stuff and I didn’t pay attention to that detail when reading Electron documentation.
Is configstore working with Windows ?

For future reference, I found this SO question that has an interesting answer using Electron API method app.getPath(name)


Unless otherwise noted, you can assume all node modules to work on OS X, Linux and Windows, including configstore.


Instead of configstore, I would now recommend electron-config, which is optimized for Electron usage.