Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store user settings in Electron (Atom Shell) Application?

Tags:

electron

I can't seem to locate a built in mechanism to store user settings. I was hoping that electron provided a standard method for storing user settings across all desktop platforms. If there isn't a precedent for this I can implement it myself, I just didn't want to jump to a custom solution immediately. Research online is pretty sparse in this area. Thanks!

like image 696
CodeManiak Avatar asked May 26 '15 17:05

CodeManiak


People also ask

Where does Electron store store data?

Typically data is stored in the user's “app data” folder. Where this directory is varies by operating system. Electron provides app. getPath which returns the right directory, depending on your platform.


2 Answers

Each platform has different default locations for different kinds of data. So, if you want to store data in default locations based on platform, check out app.getPath(name)

It retrieves a path to a special directory or file associated with name.

You can also use it to differentiate between data the user wants to save, and data your application saves that you don't want to clutter up users directories.

Or if you just want to store files reletive to a specific path you can use the app.setPath(name,path)

like image 65
Josh Avatar answered Sep 29 '22 03:09

Josh


I've faced this particular problem with my Electron app and this post inspired me to write an NPM module called electron-json-storage.

This module allows to easily write/read JSON to/from app.getPath('userData'):

const storage = require('electron-json-storage');  // Write storage.set('foobar', { foo: 'bar' }).then(function() {      // Read     storage.get('foobar').then(function(object) {         console.log(object.foo);         // will print "bar"     });  }); 
like image 45
jviotti Avatar answered Sep 29 '22 05:09

jviotti