I\'ve been scouring the Electron documentation to try and figure out how to persist data in an Electron app. For example, in iOS or OS X, you could use NSUserDefaults to store u
There is a module that gives simple methods to get and set json files to this directory, creates subdirectories if needed and supports callbacks and promises:
https://github.com/ran-y/electron-storage
Readme:
Installation
$ npm install --save electron-storage
usage
const storage = require('electron-storage');
API
storage.get(filePath, cb)
storage.get(filePath, (err, data) => {
if (err) {
console.error(err)
} else {
console.log(data);
}
});
storage.get(filePath)
storage.get(filePath)
.then(data => {
console.log(data);
})
.catch(err => {
console.error(err);
});
storage.set(filePath, data, cb)
storage.set(filePath, data, (err) => {
if (err) {
console.error(err)
}
});
storage.set(filePath, data)
storage.set(filePath, data)
.then(data => {
console.log(data);
})
.catch(err => {
console.error(err);
});
storage.isPathExists(path, cb)
storage.isPathExists(path, (itDoes) => {
if (itDoes) {
console.log('pathDoesExists !')
}
});
storage.isPathExists(path)
storage.isPathExists(path)
.then(itDoes => {
if (itDoes) {
console.log('pathDoesExists !')
}
});