userdefaults
v3.0.0
Published
User defaults for NodeJS
Downloads
10
Readme
Node User Defaults
Persistent data store for node apps.
Getting Started
The goal of this library is to provide a very straighforward way to write persistent data to disk. This can be useful when working with small amounts of data, like a simple configuration of an application or to store some preferences of a user. All data is stored in JSON format.
# Add the lib to your project and you are good to go.
$ yarn add node-user-defaults
# Not in a hurry? Use npm.
$ npm install --save node-user-defaults
Sample Code
import Store from 'node-user-defaults';
// OPTIONAL: Choose an output location for the JSON file.
// If this one is not provided, a random one will be created.
// You can always check the location via Store.getLocation().
Store.setLocation('~/.app-name');
// Storing variables is very easy and straighforward.
// You can store any type that is supported by JSON.
Store.write('darkTheme', true);
// Reading data is easy too. It's also possible to provide
// a default value in case the variable is not in the store.
const darkTheme = Store.read('darkTheme');
const name = Store.read('name', 'defaultValue');
// You can also write multiple variables at once by storing
// a plan JSON object. Easy huh?
Store.writeJson({ name: 'John' });
// Last but not least, you can query all the variables at once.
const data = Store.defaults();
Running the tests
$ git clone https://github.com/Jense5/node-user-defaults
$ cd node-user-defaults
$ yarn install
$ yarn test
Credits
- Jensen Bernard - Initial work & maintenance - Jense5
This project is licensed under the MIT License - see the license file for details.