@anujdatar/appconfig
v2.2.0
Published
persistent storage of node app configurations
Downloads
29
Maintainers
Readme
appconfig
Module for persistant configuration storage for node apps. This module is a simpler version of conf
, but is heavily based on it. Avoids use of write-file-atomic
and make-dir
because of chown permission errors with Snaps under strict confinement. Also, written in ES6.
Usage
Install package
npm i @anujdatar/appconfig
For beta/dev branch of package, if a newer test version exists
npm i @anujdatar/appconfig@next
Basic usage
const appConfig = require('@anujdatar/appconfig')
const config = new appConfig()
config.set(key, value) // adds { key: value } to the store
config.get(key) // returns value
config.delete(key) // removes { key: value } from store
Other options
Using defaults
const appConfig = require('@anujdatar/appconfig') const appDefaults = { 'foo': 'abcd', 'bar': 'pqrs' } const config = new appConfig({ defaults: appDefaults }) console.log(config.get('foo')) // abcd config.set('bar', 'wxyz') console.log(config.get('bar')) // wxyz // resetting configs config.reset('bar') // for single property // or config.reset(['foo', 'bar']) // also accepts a list of properties // or reset all props at once config.resetAll()
Specify project name explicitly
const config = new appConfig({ projectName: 'my-project' })
Adding a project suffix, if you have multiple apps named the same, or if you're creating an unofficial version of an app and want to distinguish between the two.
- projectSuffix: default is blank
Naming the config file: default filename is
config.json
- configName: default is
config
- configExt: default is
.json
- configName: default is
Using dot-prop notation
- accessByDotNotation: default
true
. If you use nested settings. Can be disabled by setting tofalse
- accessByDotNotation: default
Contributing
use npm run build
to compile index.js
in src
folder. Output in lib
folder.
Issues
Related
Deprecated and not required anymore: electron-appconfig
persistent app config storage for electron apps. Old package that used the old electron.remote
, which is deprecated in the new electron. Makes the app slower, and can be a security concern is used incorrectly.
License
MIT Copyright (c) 2019 Anuj Datar