configstore
    Overview
    Documentation
    Tutorials
    Insights
    Code
    Dependencies
    Contributors
    Jobs

configstore

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

5.0.0  •  Updated 9 months ago  •  by yeoman  •  BSD 2-Clause "Simplified" License

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.

Popularity

Weekly Downloads
5.5M
Stars
591

Maintenance

Development

Last ver 10 months ago
Created 7 years ago
Last commit 10 months ago
19 days between commits

Technology

Node version: 8.16.0
7.6K unpacked

Compliance

BSD 2-Clause "Simplified" License
OSI Approved
0 vulnerabilities

Contributors

22 contributors
Sindre Sorhus
Maintainer, 87 commits, 11 merges
Simon Boudrias
Maintainer, 7 commits, 5 merges
Works at appannie
Pascal Hartig
Maintainer, 7 commits, 2 PRs
Works at facebook
André Cruz
4 commits, 4 PRs
Works at moxystudio
Addy Osmani
Maintainer, 2 commits
Works at Google
hemanth.hm
Maintainer, 1 commits, 1 merges, 1 PRs
Works at paypal

Tags

config
store
storage
configuration
settings
preferences
json
data
persist
persistent
save
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
FacebookTwitterLinkedIn
© 2020 Devstore, Inc.