New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-user-defaults

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-user-defaults

User defaults for NodeJS

latest
Source
npmnpm
Version
3.1.1
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

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' });

// It is also possible to overwrite the whole configuration.
// So all previously stored variables will be removed.
Store.writeJson({ name: 'John' }, true);

// 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.

Keywords

node-user-defaults

FAQs

Package last updated on 11 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts