GithubHelp home page GithubHelp logo

sindresorhus / electron-store Goto Github PK

View Code? Open in Web Editor NEW
4.4K 26.0 141.0 77 KB

Simple data persistence for your Electron app or module - Save and load user preferences, app state, cache, etc

License: MIT License

JavaScript 76.32% TypeScript 23.68%
storage user-preferences config preferences electron electron-module data-persistence npm-package

electron-store's Introduction

electron-store

Simple data persistence for your Electron app or module - Save and load user settings, app state, cache, etc

Electron doesn't have a built-in way to persist user settings and other data. This module handles that for you, so you can focus on building your app. The data is saved in a JSON file named config.json in app.getPath('userData').

You can use this module directly in both the main and renderer process. For use in the renderer process only, you need to call Store.initRenderer() in the main process, or create a new Store instance (new Store()) in the main process.

Install

npm install electron-store

Requires Electron 11 or later.

Usage

const Store = require('electron-store');

const store = new Store();

store.set('unicorn', 'πŸ¦„');
console.log(store.get('unicorn'));
//=> 'πŸ¦„'

// Use dot-notation to access nested properties
store.set('foo.bar', true);
console.log(store.get('foo'));
//=> {bar: true}

store.delete('unicorn');
console.log(store.get('unicorn'));
//=> undefined

API

Changes are written to disk atomically, so if the process crashes during a write, it will not corrupt the existing config.

Store(options?)

Returns a new instance.

options

Type: object

defaults

Type: object

Default values for the store items.

Note: The values in defaults will overwrite the default key in the schema option.

schema

type: object

JSON Schema to validate your config data.

Under the hood, the JSON Schema validator ajv is used to validate your config. We use JSON Schema draft-07 and support all validation keywords and formats.

You should define your schema as an object where each key is the name of your data's property and each value is a JSON schema used to validate that property. See more here.

Example:

const Store = require('electron-store');

const schema = {
	foo: {
		type: 'number',
		maximum: 100,
		minimum: 1,
		default: 50
	},
	bar: {
		type: 'string',
		format: 'url'
	}
};

const store = new Store({schema});

console.log(store.get('foo'));
//=> 50

store.set('foo', '1');
// [Error: Config schema violation: `foo` should be number]

Note: The default value will be overwritten by the defaults option if set.

migrations

Type: object

Important: I cannot provide support for this feature. It has some known bugs. I have no plans to work on it, but pull requests are welcome.

You can use migrations to perform operations to the store whenever a version is upgraded.

The migrations object should consist of a key-value pair of 'version': handler. The version can also be a semver range.

Example:

const Store = require('electron-store');

const store = new Store({
	migrations: {
		'0.0.1': store => {
			store.set('debugPhase', true);
		},
		'1.0.0': store => {
			store.delete('debugPhase');
			store.set('phase', '1.0.0');
		},
		'1.0.2': store => {
			store.set('phase', '1.0.2');
		},
		'>=2.0.0': store => {
			store.set('phase', '>=2.0.0');
		}
	}
});

beforeEachMigration

Type: Function
Default: undefined

The given callback function will be called before each migration step.

The function receives the store as the first argument and a context object as the second argument with the following properties:

  • fromVersion - The version the migration step is being migrated from.
  • toVersion - The version the migration step is being migrated to.
  • finalVersion - The final version after all the migrations are applied.
  • versions - All the versions with a migration step.

This can be useful for logging purposes, preparing migration data, etc.

Example:

const Store = require('electron-store');

console.log = someLogger.log;

const mainConfig = new Store({
	beforeEachMigration: (store, context) => {
		console.log(`[main-config] migrate from ${context.fromVersion} β†’ ${context.toVersion}`);
	},
	migrations: {
		'0.4.0': store => {
			store.set('debugPhase', true);
		}
	}
});

const secondConfig = new Store({
	beforeEachMigration: (store, context) => {
		console.log(`[second-config] migrate from ${context.fromVersion} β†’ ${context.toVersion}`);
	},
	migrations: {
		'1.0.1': store => {
			store.set('debugPhase', true);
		}
	}
});

name

Type: string
Default: 'config'

Name of the storage file (without extension).

This is useful if you want multiple storage files for your app. Or if you're making a reusable Electron module that persists some data, in which case you should not use the name config.

cwd

Type: string
Default: app.getPath('userData')

Storage file location. Don't specify this unless absolutely necessary! By default, it will pick the optimal location by adhering to system conventions. You are very likely to get this wrong and annoy users.

If a relative path, it's relative to the default cwd. For example, {cwd: 'unicorn'} would result in a storage file in ~/Library/Application Support/App Name/unicorn.

encryptionKey

Type: string | Buffer | TypedArray | DataView
Default: undefined

Note that this is not intended for security purposes, since the encryption key would be easily found inside a plain-text Node.js app.

Its main use is for obscurity. If a user looks through the config directory and finds the config file, since it's just a JSON file, they may be tempted to modify it. By providing an encryption key, the file will be obfuscated, which should hopefully deter any users from doing so.

When specified, the store will be encrypted using the aes-256-cbc encryption algorithm.

fileExtension

Type: string
Default: 'json'

Extension of the config file.

You would usually not need this, but could be useful if you want to interact with a file with a custom file extension that can be associated with your app. These might be simple save/export/preference files that are intended to be shareable or saved outside of the app.

clearInvalidConfig

Type: boolean
Default: false

The config is cleared if reading the config file causes a SyntaxError. This is a good behavior for unimportant data, as the config file is not intended to be hand-edited, so it usually means the config is corrupt and there's nothing the user can do about it anyway. However, if you let the user edit the config file directly, mistakes might happen and it could be more useful to throw an error when the config is invalid instead of clearing.

serialize

Type: Function
Default: value => JSON.stringify(value, null, '\t')

Function to serialize the config object to a UTF-8 string when writing the config file.

You would usually not need this, but it could be useful if you want to use a format other than JSON.

deserialize

Type: Function
Default: JSON.parse

Function to deserialize the config object from a UTF-8 string when reading the config file.

You would usually not need this, but it could be useful if you want to use a format other than JSON.

accessPropertiesByDotNotation

Type: boolean
Default: true

Accessing nested properties by dot notation. For example:

const Store = require('electron-store');

const store = new Store();

store.set({
	foo: {
		bar: {
			foobar: 'πŸ¦„'
		}
	}
});

console.log(store.get('foo.bar.foobar'));
//=> 'πŸ¦„'

Alternatively, you can set this option to false so the whole string would be treated as one key.

const store = new Store({accessPropertiesByDotNotation: false});

store.set({
	`foo.bar.foobar`: 'πŸ¦„'
});

console.log(store.get('foo.bar.foobar'));
//=> 'πŸ¦„'

watch

Type: boolean
Default: false

Watch for any changes in the config file and call the callback for onDidChange or onDidAnyChange if set. This is useful if there are multiple processes changing the same config file, for example, if you want changes done in the main process to be reflected in a renderer process.

Instance

You can use dot-notation in a key to access nested properties.

The instance is iterable so you can use it directly in a for…of loop.

.set(key, value)

Set an item.

The value must be JSON serializable. Trying to set the type undefined, function, or symbol will result in a TypeError.

.set(object)

Set multiple items at once.

.get(key, defaultValue?)

Get an item or defaultValue if the item does not exist.

.reset(...keys)

Reset items to their default values, as defined by the defaults or schema option.

Use .clear() to reset all items.

.has(key)

Check if an item exists.

.delete(key)

Delete an item.

.clear()

Delete all items.

This resets known items to their default values, if defined by the defaults or schema option.

.onDidChange(key, callback)

callback: (newValue, oldValue) => {}

Watches the given key, calling callback on any changes.

When a key is first set oldValue will be undefined, and when a key is deleted newValue will be undefined.

Returns a function which you can use to unsubscribe:

const unsubscribe = store.onDidChange(key, callback);

unsubscribe();

.onDidAnyChange(callback)

callback: (newValue, oldValue) => {}

Watches the whole config object, calling callback on any changes.

oldValue and newValue will be the config object before and after the change, respectively. You must compare oldValue to newValue to find out what changed.

Returns a function which you can use to unsubscribe:

const unsubscribe = store.onDidAnyChange(callback);

unsubscribe();

.size

Get the item count.

.store

Get all the data as an object or replace the current data with an object:

const Store = require('electron-store');

const store = new Store();

store.store = {
	hello: 'world'
};

.path

Get the path to the storage file.

.openInEditor()

Open the storage file in the user's editor.

Returns a promise that resolves when the editor has been opened, or rejects if it failed to open.

initRenderer()

Initializer to set up the required ipc communication channels for the module when a Store instance is not created in the main process and you are creating a Store instance in the Electron renderer process only.

In the main process:

const Store = require('electron-store');

Store.initRenderer();

And in the renderer process:

const Store = require('electron-store');

const store = new Store();

store.set('unicorn', 'πŸ¦„');
console.log(store.get('unicorn'));
//=> 'πŸ¦„'

FAQ

Can I use YAML or another serialization format?

The serialize and deserialize options can be used to customize the format of the config file, as long as the representation is compatible with utf8 encoding.

Example using YAML:

const Store = require('electron-store');
const yaml = require('js-yaml');

const store = new Store({
	fileExtension: 'yaml',
	serialize: yaml.safeDump,
	deserialize: yaml.safeLoad
});

How do I get store values in the renderer process when my store was initialized in the main process?

The store is not a singleton, so you will need to either initialize the store in a file that is imported in both the main and renderer process, or you have to pass the values back and forth as messages. Electron provides a handy invoke/handle API that works well for accessing these values.

ipcMain.handle('getStoreValue', (event, key) => {
	return store.get(key);
});
const foo = await ipcRenderer.invoke('getStoreValue', 'foo');

Can I use it for large amounts of data?

This package is not a database. It simply uses a JSON file that is read/written on every change. Prefer using it for smaller amounts of data like user settings, value caching, state, etc.

If you need to store large blobs of data, I recommend saving it to disk and to use this package to store the path to the file instead.

Related

electron-store's People

Contributors

bendingbender avatar brandon93s avatar doncicuto avatar husek avatar kiavashp avatar kwangure avatar mehedih avatar popod avatar rafaelramalho19 avatar richienb avatar robbiethewagner avatar rroessler avatar sandersn avatar sindresorhus avatar trodi avatar vaaski avatar yaodingyd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

electron-store's Issues

Migrations

Would be useful to have forward migration support built-in. You define the version when something changed and a function where you can manipulate the store and the correct migrations will be applied according to the installed version on the first run after an update.

Quick braindump API:

const Store = require('electron-store');

const migrations = {
	'1.0.0': store => {
		const old = store.get('old');
		store.set('new', old);
		store.delete('old');
	}
};

const store = new Store({migrations});

I'm open to feedback.

Invalid JSON file corrupts store data

When the file that is passed to the store options is not a valid JSON, the contents of the file are overwritten to an empty object. Is there any built-in way to overcome this or should I check the validity of the file before calling the ctor of the store?

Cannot read property 'filename' of undefined

Hi,

I'm trying to build app using electron config but I have trouble with npm run package using this module.

$ git clone https://github.com/chentsulin/electron-react-boilerplate
$ cd electron-react-boilerplate
$ npm run dev # GOOD
$ npm run package # GOOD

$ # Import electron-config
$ git diff
--- a/app/main.development.js
+++ b/app/main.development.js
@@ -1,4 +1,5 @@
 import { app, BrowserWindow, Menu, shell } from 'electron';
+import Config from 'electron-config'

 let menu;
 let template;

$ npm run dev # GOOD
$ npm run package # FAILS (both on windows and linux)
# Uncaught Exception:
# TypeError: Cannot read prperty 'filename' of undefined

More general name needed

IMHO, this package can be used for either the config or just for saving/caching data (like we're doing it in Now Desktop). Because of this, I recommend renaming it.

My suggestion is "electron-store" (the package name is available on npm).

wrong encryptionKey just overwrites the file?

I am doing this

store = new Store({
        name : 'encrypted_config',
        encryptionKey : 'test123',
});

When the app restarts and I try to do this

store = new Store({
        name : 'encrypted_config',
        encryptionKey : 'xyz123',
});

it just creates a new file instead of throwing error or something, am I missing something?

Include support for JSON schema

Issuehunt badges

Can be useful to ensure you only set the correct types in your config, and could validate if the config file is manually edited by the user.

https://github.com/epoberezkin/ajv looks like the best one.

Thoughts? Would you use this?


Note: This should be implemented in conf first.

yaodingyd earned $100.00 by resolving this issue!

Explain why it's not a singleton

It's easy to think that it would make for a simpler API. No need to initialize it first. I thought so too at first.

But imagine if it had been a singleton:

index.js

const config = require('electron-config');
const someComponent = require('./some-component');

config.setDefaults({
  foo: true
});

…

config.get('foo');
//=> true

some-component.js

const config = require('electron-config');

…

config.get('foo');
//=> undefined

Note the undefined. So you would have to be careful about setting the defaults before any app imports, which is easy to forget.


The following a much safer and explicit pattern:

config.js

const config = require('electron-config');

module.exports = new Config({
  foo: true
});

index.js

const config = require('./config');
const someComponent = require('./some-component');

…

config.get('foo');
//=> true

some-component.js

const config = require('./config');

…

config.get('foo');
//=> true

Thoughts on this?

Windows line ends

Hi, I was just wondering if there is a way to set electron store to use the full CR+LF windows line ends, so that my application users can open the files in Notepad? (currently it uses unix line ends so the file doesn't display properly unless they use an IDE/Notepad++ etc). Thanks if you can help!

If user was prompted for an encryptionKey

You said in your readme that encryptionKey is not meant for security. But what if I prompt user everytime the app is opened for encryptionKey and never store it in App's code itself, will that be secured enough?

Crash when running as a packaged app with electron-builder on macOS

Uncaught Exception:
TypeError: Expected string, got undefined
    at module.exports.name ([...]IRCCloud.app/Contents/Resources/app.asar/node_modules/env-paths/index.js:49:9)
    at ElectronConfig.Conf ([...]IRCCloud.app/Contents/Resources/app.asar/node_modules/conf/index.js:29:9)
    at ElectronConfig ([...]IRCCloud.app/Contents/Resources/app.asar/node_modules/electron-config/index.js:11:3)
    at setupConfig ([...]IRCCloud.app/Contents/Resources/app.asar/main.js:56:10)
    at Object.<anonymous> ([...]IRCCloud.app/Contents/Resources/app.asar/main.js:60:16)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)

env-paths expects a String, but conf is passing in an undefined opts.projectName, because electron-config is setting opts.cwd directly so it isn't needed.

This fails because the package.json isn't bundled into the asar file when built, so pkg-up finds nothing.

Not sure which package this should be fixed in.


Also, a fresh npm install results in this version tree:

└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected]

conf depends on env-paths: ^0.2.0 which won't allow 0.3.0

When will new version release?

Version 2.0.0 seems not work on electron 4.

Module not found: Error: Can't resolve 'worker_threads' in write-file-atomic

Override via ENV vars

I think a great enhancement would be the ability to override values with env vars. This would give us the ability to use the store as the single source of truth in out app. Today in order to do this we will need to abstract out a layer and have an object as our single source of truth and load items into this object (either by electron-store or env vars). Because of this we lose the ability to listen to onChange events which is a fantastic feature of the library.

Setting url as key not working

const Store = require('electron-store');
const appStore = new Store();

var item = {
     "https://mail.google.com/mail/": { 
            "metadata": {
                    "name": default mail client"
              }
        }
};

appStore.set(item);

[feature] possibility to set config file location

Your lib looks perfect to me, but I need possibility to set where config should be saved (basically app is for devs and i need some .rc file in ~ so it can persist after update & allow someone to edit it quickly). Is it hard to make?
Also it could be nice if I can pass json object in a store constructor as a first state, so I can actually manually sync data to file as a "backup" config

Encryption

I've supplied an encryption key when creating a new store, but nothing happens. Could you please elaborate on whats required / how this works?

error in render process

I see the docs says that the module can use in both render and main process,but i use the module in main process,it seems to have some error.How can use the module in render process?
b1
b2

doesn't work with webpack

If I require this module in webpack, it will break webpack because of this line
const parentDir = path.dirname(module.parent.filename);

Is there any way to make it work webpack, maybe refer to the global.module instead of just module?

I'm using:

  • electron-config: 0.2.1
  • electron: 1.4.1
  • webpack: 1.13.2

Update Object Array via config.set

const items: [
  {'data1':true},
  {'data2':false}
]

How can I config.set('items[0].data1',false)?

Currently, I do config.get('items') and loop through updating the values and then doing config.set('items') which works but feels backward.

App Data Persists after App Delete

The default location for stores (~/.config/AppName on linux) is not deleted when the app is uninstalled. Is this intentional? Do you have a recommendation for how to delete the data when the app is deleted?

EPERM operation not permitted, rename on windows only

Have been using electron store in mac perfectly, but when packaged for windows it randomly throws this error:

capture

When you click ok it carries on absolutely fine.

It seems windows doesn't let you store.set anything new during some processes... it looks to coincide with writing files with node.js but I can't be sure, does it 'lock' the config.json file at any point for any reason? Does this make sense to anyone? I'm really stuck on this and don't want to replace electron.store as a last resort as it's perfect otherwise!

How to append a list/array?

What I've known is to get and append and set .

list = store.get('list')
list.push(foo)
store.set('list', list)

Is this the only way?

Any shortcuts like store.push('list', foo)

Thanks~

The `onDidChange` event is not propagating to all windows

I've got two windows open. One of them changes the state object.

store.set('preferences', newPrefs)

document.addEventListener('DOMContentLoaded', () => {
  store.onDidChange('preferences', (newValue, oldValue) => {
    console.log('hello from setting window', newValue, oldValue)
    // works!
  })
})

Another open window is also subscribed to the event, but it doesn't fire:

document.addEventListener('DOMContentLoaded', () => {
  store.onDidChange('preferences', (newValue, oldValue) => {
    console.log('hello from receiving window', newValue, oldValue)
    // does not work :[
  })
})

Cannot find module "."

Uncaught Error: Cannot find module "."
    at webpackMissingModule (index.js:25)
    at ElectronStore.Conf (index.js:25)
    at ElectronStore (index.js:20)
    at Object../app/actions/recent-projects.js (recent-projects.js:4)
    at __webpack_require__ (bootstrap 92e2fd3…:677)
    at fn (bootstrap 92e2fd3…:87)
    at Object../app/containers/HomePage.js (HomePage.js:8)
    at __webpack_require__ (bootstrap 92e2fd3…:677)
    at fn (bootstrap 92e2fd3…:87)
    at Object../app/routes.js (routes.js:5)

Have this error in one of my project. Unluckily, I cannot provide the source code.

Store tries to read JSON file with wrong filename

Hi,

I recently upgraded my application to version 1.3.0 of the library and the following initialization fails:

const store = new Store({
    name: 'maps',
    cwd: `${__dirname}/assets`
});

with error:

Error: ENOENT, assets\maps.json.714842314 not found in D:\myapp\resources\app.asar

The file is maps.json and exists inside assets folder. When I build my application using electron-packager, for some reason, electron-store tries to read the file as maps.json.<random number> .

Maybe because of atomic writing feature in the conf module? If I lock conf in version 1.1.2 it works fine.

Thanks

Multiple instance store

It seems if I want to run multiple instances of one app with different data configs. It would write into the same config.json file. Is there a recommended way of using it with multiple instances, or using something else?

Failed to minify the code.

Hey There,

Using this in our Electron app, which is a React app.

When I run npm run build I get the following error message:

Failed to minify the code from this file: 

 	./node_modules/electron-store/index.js:6 

Read more here: http://bit.ly/2tRViJ9

If you follow the link it says to:

Open an issue on the dependency's issue tracker and ask that the package be published pre-compiled.

Let me know your thoughts on this.

Thanks!

Getting "Critical dependency" error with webpack

Hi,
I'm using the electron-vue boilerplate.
When I add the line const Config = require('electron-config'); I get the following error:

Failed to compile.
./~/conf/index.js
21:27-43 Critical dependency: the request of a dependency is an expression

Any idea why?
Thanks

Support dates

Issuehunt badges

Would be nice if you could store.set('foo', new Date()) and get back a Date object when you do store.get('foo'). Could probably make use of the second argument to JSON.parse(). We need to save some kind of information to indicate that it's a native Date format. Maybe a separate __meta__ key or something. Suggestions welcome.


IssueHunt Summary

Backers (Total: $80.00)

Submitted pull Requests


Become a backer now!

Or submit a pull request to get the deposits!

Tips

Support for overriding file extension

This may be out of scope for the intended purpose of the module. Currently you can't override the extension used, just the name and location. With the move to a more generic name (#4) to represent a larger use case for this module, does it make sense to allow overriding the extension?

For example, I could use electron-store to interact with a file with a custom file extension that can be associated with my electron app. These might be simple save/export/preference files that are intended to be shareable or saved outside of the application. It may still be a json file or an "encrypted" json file, but the user need not know that.

  1. Is this use case something the module is okay supporting?
  2. If so, are you open to a PR?

Convenience methods

I propose adding some convenience methods to make common things easier.

What I do most of the time when using electron-store is to get a boolean and invert it. For example, store.set('isFoo', !store.get('isFoo')).

Would be nice to have:

.toggleBoolean(key) which accepts a key and toggles the boolean.

.appendToArray(key, newItem) which pushes a new item to the array. (#32)

.modify(key, mutateCallback) which would give you a callback to modify the value that you then return in the callback:

Before:

const array = store.get('array');
array.find(element => element.title === 'baz').src = 'something';
store.set('array', array);

After:

store.modify('array', array => {
    array.find(element => element.title === 'baz').src = 'something';
    return array;
});

These methods will require you to specify the key in the defaults option, so it would always work. If you try to use toggleBoolean() and the underlaying value is of a different type, it would throw an error.

Any other convenience methods we could add? I'm also interested in feedback on the method names.


*Note: While I opened the issue here, the methods we eventually go for should be added to conf.

Using store with redux

I am using electron-store to re-hydrate the state of my redux store on app load. I am noticing that the setters and getters on store properties are showing up in my redux store. Is there an easy way to get values out of the store as properties that way I can keep my store pure and serializable?

I know that I can JSON.stringify() and then JSON.parse() to get rid of the getters and setters but that seems kind of inefficient? Any help on answering this would be appreciated!

More detail on usage in Main vs Renderer processes

I am using Electron and React to create a web app, and the documentation for electron-config does not show how to carry out IPC (inter-process communication) between processes.

In the case of React, the render process would be a component. How do I use electron-config with my React component and send the user data over to the main Electron process?

Thanks

Append item to Stored json array (QUESTION)

Is there a way I can append an item to a list that is stored? For example:

store.set("listOfItems", [{ "name" : "John"}])

how would I then add another item to store.get("listOfItems")
thanks for any help from anyone

Defaults not working

Hello,
when doing the following, this is what I get:

import Config from 'electron-config';

const config = new Config({ 'locale': "en-US" });

console.log(config.get('locale'));
// ==> undefined
console.log(config.store);
// ==> {}

Why is that? Am I doing something wrong perhaps?
Thank you.

Doesnt work with Webpack

You close and lock issues but they arent resolved - this doesnt work with webpack. Locking the issue so no one can post in it and provide solutions only makes the issue far worse. Asking to just go ask in webpack doesnt help solve the problem when people run into it and is EXTREMELY upsetting and annoying. If you didn't lock it to purposefully make it hard to fix this issue then perhaps people would have provided more solutions to find one that works for everyone...

Store Encryption Not Working

Store file is not being encrypted.

Here is an example to help you visualize the issue:

var store = new Store({
    name: "myExample",
    encryptionKey: "oiV32mVp5lOwYneFESjrWq2xFByNOvNj"
})

store.set("this_is_a_key", "this_is_a_value")

And the result, a non-encrypted store file:

{
    "this_is_a_key": "this_is_a_value"
}

Refer to this issue for more information: #26

Default usage not working

Just tried the default usage from the readme. I get this error:

/Users/yann/Development/electron-config-test/node_modules/electron-config/index.js:8
		opts.cwd = (electron.app || electron.remote.app).getPath('userData');
		                                           ^

TypeError: Cannot read property 'app' of undefined
    at ElectronConfig (/Users/yann/Development/electron-config-test/node_modules/electron-config/index.js:8:46)
    at Object.<anonymous> (/Users/yann/Development/electron-config-test/index.js:3:16)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)

By the way, why is not electron a dependency in electron-config (got Cannot find module 'electron' error when electron not installed)?

https://gist.github.com/yannbertrand/c2f6f246df2c35e45a2bba7237688da3
[email protected]
[email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.