yeoman/configstore


Easily load and persist config without having to think about where and how

License: BSD-2-Clause

Language: JavaScript


configstore Build Status

Easily load and persist config without having to think about where and how

The config is stored in a JSON file located in $XDG_CONFIG_HOME or ~/.config.
Example: ~/.config/configstore/some-id.json

If you need this for Electron, check out electron-store instead.
And check out conf for an updated approach to this concept.

Install

$ npm install configstore

Usage

const Configstore = require('configstore');
const packageJson = require('./package.json');

// Create a Configstore instance
const config = new Configstore(packageJson.name, {foo: 'bar'});

console.log(config.get('foo'));
//=> 'bar'

config.set('awesome', true);
console.log(config.get('awesome'));
//=> true

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

config.delete('awesome');
console.log(config.get('awesome'));
//=> undefined

API

Configstore(packageName, defaults?, options?)

Returns a new instance.

packageName

Type: string

Name of your package.

defaults

Type: object

Default config.

options

Type: object

globalConfigPath

Type: boolean
Default: false

Store the config at $CONFIG/package-name/config.json instead of the default $CONFIG/configstore/package-name.json. This is not recommended as you might end up conflicting with other tools, rendering the "without having to think" idea moot.

configPath

Type: string
Default: Automatic

Please don't use this option unless absolutely necessary and you know what you're doing.

Set the path of the config file. Overrides the packageName and globalConfigPath options.

Instance

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

.set(key, value)

Set an item.

.set(object)

Set multiple items at once.

.get(key)

Get an item.

.has(key)

Check if an item exists.

.delete(key)

Delete an item.

.clear()

Delete all items.

.size

Get the item count.

.path

Get the path to the config file. Can be used to show the user where the config file is located or even better open it for them.

.all

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

config.all = {
	hello: 'world'
};

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Project Statistics

Sourcerank 19
Repository Size 79.1 KB
Stars 548
Forks 45
Watchers 20
Open issues 0
Dependencies 8
Contributors 20
Tags 30
Created
Last updated
Last pushed

Top Contributors See all

Sindre Sorhus Simon Boudrias Pascal Hartig André Cruz Bret Comnes Mat Scales Addy Osmani Krishnan Anantheswaran noffle Eran Tiktin Moritz Kröger Max Hallinan Jason Dent wtgtybhertgeghgtwtg Kevin Mårtensson Zeno Rocha Kyle E. Mitchell Siddharth Kannan hemanth.hm Simon Hürlimann

Packages Referencing this Repo

configstore
Easily load and save config without having to think about where and how
Latest release 5.0.0 - Updated - 548 stars

Recent Tags See all

v5.0.0 June 11, 2019
v4.0.0 July 28, 2018
v3.1.2 March 26, 2018
v3.1.1 July 20, 2017
v3.1.0 May 10, 2017
v3.0.0 February 13, 2017
2.1.0 February 11, 2017
v2.1.0 September 01, 2016
v2.0.0 March 01, 2016
v1.4.0 December 09, 2015
v1.3.0 October 27, 2015
v1.2.1 August 04, 2015
1.2.0 June 30, 2015
1.1.0 June 09, 2015
v1.0.0 April 29, 2015

Interesting Forks See all

defconcepts/configstore
Easily load and persist config without having to think about where and how
JavaScript - Updated - 2 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-06-21 02:50:19 UTC

Login to resync this repository