https://github.com/perry-mitchell/user-config
Easy user application configuration management
https://github.com/perry-mitchell/user-config
config configuration configuration-file nodejs settings settings-storage user-profile
Last synced: about 1 year ago
JSON representation
Easy user application configuration management
- Host: GitHub
- URL: https://github.com/perry-mitchell/user-config
- Owner: perry-mitchell
- License: mit
- Created: 2017-05-03T17:56:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-03T19:53:28.000Z (about 9 years ago)
- Last Synced: 2025-04-11T13:10:27.022Z (about 1 year ago)
- Topics: config, configuration, configuration-file, nodejs, settings, settings-storage, user-profile
- Language: JavaScript
- Size: 4.88 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# user-config
Easy user application configuration management
[](https://travis-ci.org/perry-mitchell/user-config) [](https://www.npmjs.com/package/user-config)
## Usage
When requiring the library, **user-config** returns a function which is used to instantiate a config object that allows getting and setting of config values:
```javascript
const createConfig = require("user-config");
const config = createConfig("my-app");
// items in config are stored in objects and must be serialisable
config.set("some.config.item", 123);
```
Configuration changes should be saved after being changed:
```javascript
const config = require("user-config")("my-app");
config.set("port", 443);
config.save();
```
Values can easily be retrieved from the store, including entire objects:
```javascript
const config = require("user-config")("my-app");
console.log(`Application running on interface ${config.get("listen.ip")}`);
```
### Templating
Outdated configurations can be updated using a templating system. By passing a template to the creation of the config store, old configurations can be merged with the template to ensure the presence of keys and structures:
```javascript
const createConfig = require("user-config");
const TEMPLATE = {
ip: "0.0.0.0",
encryption: {
mode: "aes-gcm"
}
}
const config = createConfig("my-app", TEMPLATE);
config.get("encryption.mode"); // "aes-gcm"
```
## Browser usage
When being used in the context of a browser, **user-config** knows to use `localStorage` instead of the filesystem. Storage switching is transparent.